forked from LaunchCodeEducation/HTTP-and-Forms-Studio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
41 lines (33 loc) · 1.12 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<!doctype html>
<head>
<meta charset="utf-8">
<script>
// TODO: create a handler
function setSearchEngine(){
let actions = {
"google": "https://www.google.com/",
"duckDuckGo": "https://duckduckgo.com/",
"bing": "https://www.bing.com/search",
"ask": "https://www.ask.com/web"
}
let engine = document.querySelector('[name=engine]:checked');
let searchForm = document.getElementById("searchForm");
let action = actions[engine.value];
searchForm.setAttribute("action", action);
}
window.addEventListener("load", function(){
let goButton = document.getElementById("searchForm");
goButton.addEventListener("submit", setSearchEngine);
});
</script>
</head>
<body>
<form id="searchForm">
<input name="q" type="text" />
<label><input type="radio" name="engine" value="google"/>Google</label>
<label><input type="radio" name="engine" value="duckDuckGo"/>DuckDuckGo</label>
<label><input type="radio" name="engine" value="bing"/>Bing</label>
<label><input type="radio" name="engine" value="ask"/>Ask</label>
<input type="submit" value="Go!" />
</form>
</body>