Skip to content

Commit a9e7cdc

Browse files
committed
forms
1 parent c8f8ae6 commit a9e7cdc

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,44 @@
33
<head>
44
<meta charset="utf-8">
55
<script>
6+
function setSearchEngine(){
7+
8+
const buttonSelection=document.querySelector("input[name=engine]:checked");
9+
let url=actions[buttonSelection.value];
10+
form.action=url;
11+
console.log("go button clicked");
12+
let querySelector = document.querySelector("[name=engine]:checked");
13+
console.log(querySelector);
14+
}
15+
let actions= {
16+
google: "https://www.google.com/search",
17+
duckDuckGo: "https://www.duckduckgo.com/search",
18+
bling: "https:// www.bling.com/search",
19+
ask: "https://www.ask.com/search",
20+
21+
}
22+
623
// TODO: create a handler
724
window.addEventListener("load", function(){
825
// TODO: register the handler
26+
const form =document.getElementById("searchForm");
27+
form.addEventListener("submit", setSearchEngine);
928
});
1029
</script>
1130
</head>
1231

1332
<body>
1433

1534
<form id="searchForm">
16-
<!-- TODO: add form elements -->
17-
</form>
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>
41+
</form>
42+
43+
44+
1845

1946
</body>

0 commit comments

Comments
 (0)