Skip to content

Commit 4ff540c

Browse files
committed
studio minus bonus mission
1 parent cc14ffc commit 4ff540c

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

user-input-with-forms/studio/index.html

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,35 @@
33
<head>
44
<meta charset="utf-8">
55
<script>
6-
// TODO: create a handler
6+
function setSearchEngine() {
7+
let actions = {
8+
"google": "https://www.google.com/",
9+
"duckDuckGo": "https://duckduckgo.com/",
10+
"bing": "https://www.bing.com/search",
11+
"ask": "https://www.ask.com/web"
12+
}
13+
const form = document.getElementById('searchForm')
14+
let selectedEngine = document.querySelector("input[name=engine]:checked");
15+
let action = actions[selectedEngine.value];
16+
form.action=action;
17+
}
718
window.addEventListener("load", function(){
8-
// TODO: register the handler
19+
const form = document.getElementById("searchForm");
20+
form.addEventListener("submit", setSearchEngine);
921
});
1022
</script>
1123
</head>
1224

1325
<body>
1426

1527
<form id="searchForm">
16-
<!-- TODO: add form elements -->
28+
<input type="text" id="q" name="q"/>
29+
<label><input type="radio" name="engine" value="google"/>Google</label>
30+
<label><input type="radio" name="engine" value="duckDuckGo"/>DuckDuckGo</label>
31+
<label><input type="radio" name="engine" value="bing"/>Bing</label>
32+
<label><input type="radio" name="engine" value="ask"/>Ask</label>
33+
<button type="submit" value="GO!">GO!</button>
34+
1735
</form>
1836

1937
</body>

0 commit comments

Comments
 (0)