forked from LaunchCodeEducation/HTTP-and-Forms-Studio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
58 lines (52 loc) · 1.74 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<!doctype html>
<head>
<meta charset="utf-8">
<link href="https://fonts.googleapis.com/css2?family=Jost:wght@400;700&display=swap" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="styles.css">
<script>
let actions = {
"google": "https://www.google.com/search",
"duckDuckGo": "https://duckduckgo.com/",
"bing":"https://www.bing.com/search",
"ask":"https://www.ask.com/web",
}
function setSearchEngine(event) {
let selectedEngine = document.querySelector("input[name=engine]:checked");
let inputText = document.querySelector("input[name=q]").value;
if (selectedEngine === null) {
alert("Please select engine")
event.preventDefault();
} else if (inputText === "") {
alert("I need something to search!")
event.preventDefault();
} else {
let engineName = selectedEngine.value;
document.getElementById("searchForm").action = actions[engineName];
console.log(inputText)
// event.preventDefault();
}
}
window.addEventListener("load", function(){
let form = document.getElementById("searchForm"); // or can use querySelector("form") but not specific
form.addEventListener("submit", setSearchEngine);
});
</script>
</head>
<body>
<div>
<h1>Pick Yer Serch</h1>
<form id="selection">
<label><input type="radio" name="engine" value="google">Google</label><br>
<label><input type="radio" name="engine" value="duckDuckGo">Duck Duck Go!</label><br>
<label><input type="radio" name="engine" value="bing">Bing</label><br>
<label><input type="radio" name="engine" value="ask">Ask</label><br>
</form>
</div>
<div>
<h1>What you want?</h1>
<form id="searchForm" action="">
<input id="queryWord" type="text" name="q"/>
<button value="userQuery">Submit</button>
</form>
</div>
</body>