Skip to content

Commit 0611095

Browse files
committed
Studio complete
1 parent 4876c33 commit 0611095

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

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

Lines changed: 23 additions & 4 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
6+
let actions = {
7+
"google": "https://www.google.com/search",
8+
"duckduckgo": "https://www.ducduckgo.com/",
9+
"bing": "https://www.bing.com/search",
10+
"ask": "https://www.ask.com/web"
11+
};
12+
13+
function setSearchEngine(){
14+
const buttonSelected = document.querySelector('input[name=engine]:checked');
15+
const form = document.getElementById("searchForm");
16+
let actionURL = actions[buttonSelected.value];
17+
form.action = actionURL;
18+
}
719
window.addEventListener("load", function(){
820
// TODO: register the handler
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 -->
17-
</form>
29+
<form id="searchForm" target="_blank">
30+
<input type="text" id="q" name="q"/>
31+
<label>Google<input type="radio" name="engine" value="google"/></label>
32+
<label>DuckDuckGo<input type="radio" name="engine" value="duckduckgo"/></label>
33+
<label>Bing<input type="radio" name="engine" value="bing"/></label>
34+
<label>Ask<input type="radio" name="engine" value="ask"/></label>
35+
<button id="submit" value="Go!">Submit</button>
1836

37+
</form>
1938
</body>

0 commit comments

Comments
 (0)