forked from LaunchCodeEducation/HTTP-and-Forms-Studio
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
64 lines (45 loc) · 1.43 KB
/
index.html
File metadata and controls
64 lines (45 loc) · 1.43 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!doctype html>
<head>
<meta charset="utf-8">
<script>
function setSearchEngine() {
// get selected input node
let selectedNode = document.querySelector("input[name=engine]:checked");
// get the selected value
let selectedValue = selectedNode.value;
// use the value to determine search URL/form action
let actions = {
"google": "https://www.google.com/search",
"duckDuckGo": "https://duckduckgo.com/",
"bing": "https://www.bing.com/search",
"ask": "https://www.ask.com/web"
};
let actionUrl = actions[selectedValue];
// set the "action" attribute of the form
let formNode = document.getElementById("searchForm");
formNode.setAttribute("action", actionUrl);
}
window.addEventListener("load", function(){
let formNode = document.getElementById("searchForm");
formNode.addEventListener("submit", setSearchEngine);
});
</script>
</head>
<body>
<form id="searchForm">
<input type="text" name="q">
<label>Google
<input type="radio" name="engine" value="google">
</label>
<label>DuckDuckGo
<input type="radio" name="engine" value="duckDuckGo">
</label>
<label>Bing
<input type="radio" name="engine" value="bing">
</label>
<label>Ask
<input type="radio" name="engine" value="ask">
</label>
<input type="submit" value="Go!">
</form>
</body>