Skip to content

Commit 49d9f1f

Browse files
Quinton KornegayQuinton Kornegay
Quinton Kornegay
authored and
Quinton Kornegay
committed
studio forms
1 parent 1b75862 commit 49d9f1f

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

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

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

1327
<body>
1428

15-
<form id="searchForm">
16-
<!-- TODO: add form elements -->
29+
<form id="searchForm" target="_blank">
30+
<input type="text" id="q" name="q"/>
31+
<label><input type="radio" name="engine" value="google" /> Google</label>
32+
<label><input type="radio" name="engine" value="duckDuckGo" /> DuckDuckGo</label>
33+
<label><input type="radio" name="engine" value="bing" /> Bing</label>
34+
<label><input type="radio" name="engine" value="ask" /> Ask</label>
35+
<button id="submit" value="Go!">Go!</button>
1736
</form>
18-
37+
1938
</body>

0 commit comments

Comments
 (0)