forked from LaunchCodeEducation/HTTP-and-Forms-Studio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
54 lines (50 loc) · 1.57 KB
/
index.html
File metadata and controls
54 lines (50 loc) · 1.57 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
<!DOCTYPE html>
<head>
<meta charset="utf-8" />
<script>
let actions = {
google: "https://www.google.com/",
duckDuckGo: "https://duckduckgo.com/",
bing: "https://www.bing.com/search",
ask: "https://www.ask.com/web",
};
function setSearchEngine() {
let form = document.getElementById("searchForm");
let selected = document.querySelector("input[name=engine]:checked");
if (selected !== null) {
form.action = actions[selected.value];
} else {
window.alert("Selection required");
event.preventDefault();
}
let query = document.getElementById("q").value;
if (query === "") {
window.alert("Input required");
event.preventDefault();
}
}
window.addEventListener("load", function () {
let submitBtn = document.getElementById("submitBtn");
submitBtn.addEventListener("click", function () {
setSearchEngine();
});
});
</script>
</head>
<body>
<form action="" id="searchForm">
<label>query<input type="text" name="q" id="q" /></label>
<br />
<label>Google<input type="radio" name="engine" value="google" /></label>
<br />
<label
>DuckDuckGo<input type="radio" name="engine" value="duckDuckGo"
/></label>
<br />
<label>Bing<input type="radio" name="engine" value="bing" /></label>
<br />
<label>Ask<input type="radio" name="engine" value="ask" /></label>
<br />
<input type="submit" name="" id="submitBtn" value="go" />
</form>
</body>