Skip to content

Commit 354db84

Browse files
committed
repush
1 parent 5f065d9 commit 354db84

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

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

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,41 @@
33
<head>
44
<meta charset="utf-8">
55
<script>
6-
// TODO: create a handler
6+
let actions = {
7+
google: "https://www.google.com/search",
8+
duckDuckGo: "https://duckduckgo.com/",
9+
bing: "https://www.bing.com/search",
10+
ask: "https://www.ask.com/web"
11+
}
12+
function setSearchEngine() {
13+
const buttonChosen = document.querySelector("input[name=engine]:checked");
14+
let input = document.querySelector("input[name=q]");
15+
if (!buttonChosen){
16+
alert("Choose a button!")
17+
};
18+
if (input.value === ""){
19+
alert("Please enter a query!")
20+
};
21+
searchForm.action = actions[buttonChosen.value]
22+
};
23+
724
window.addEventListener("load", function(){
8-
// TODO: register the handler
9-
});
25+
const form = document.getElementById("searchForm");
26+
form.addEventListener('submit', setSearchEngine);
27+
});
28+
1029
</script>
1130
</head>
1231

1332
<body>
1433

15-
<form id="searchForm">
16-
<!-- TODO: add form elements -->
34+
<form id="searchForm" target_blank >
35+
<input type = "text" name ="q" />
36+
<label> <input type = "radio" name ="engine" value = "google" </> Google</label>
37+
<label> <input type = "radio" name ="engine" value = "duckDuckGo" </> DuckDuckGo</label>
38+
<label> <input type = "radio" name ="engine" value = "bing" </> Bing</label>
39+
<label> <input type = "radio" name ="engine" value = "ask" </> Ask</label>
40+
<button id="submit" value = "Go!"> Go! </button>
1741
</form>
1842

1943
</body>

0 commit comments

Comments
 (0)