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 (48 loc) · 2.03 KB
/
index.html
File metadata and controls
54 lines (48 loc) · 2.03 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 setSearchEngine = function(){
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 form = document.getElementById('searchForm');
let selectedEngine = document.querySelector("[name=engine]:checked")
let action = actions[selectedEngine.value];
form.setAttribute('action' , action);
}
window.addEventListener('load', function(){
let form = document.getElementById('searchForm');
form.addEventListener('submit', function(setSearchEngine){
let validateSearchEngineInput = document.querySelector("input[name=engine]");
let validateSearchStringInput = document.querySelector("input[name=q]");
if (!validateSearchEngineInput.value || !validateSearchStringInput.value) {
alert("All fields are required");
setSearchEngine.preventDefault();
} else {
form.addEventListener('submit', setSearchEngine);
}
});
});
window.addEventListener('load', function(){
let form = document.getElementById('searchForm');
form.addEventListener('submit', setSearchEngine);
});
alert("User Has Submitted Form");
alert("User has selected: " + validateSearchEngineInput.value);
alert("User has selected: " + validateSearchEngineInput.value + "");
</script>
</head>
<body>
<form id="searchForm">
<label><input type="text" name="q"/></label>
<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>
<label><input type="submit" value="Go!"/></label>
</form>
</body>