|
| 1 | + |
1 | 2 | <!doctype html>
|
2 | 3 |
|
3 | 4 | <head>
|
4 | 5 | <meta charset="utf-8">
|
5 | 6 | <script>
|
| 7 | + function setSearchEngine() { |
| 8 | + let button = document.querySelector("input[name=engine]:checked"); |
| 9 | + console.log("set search engine"); |
| 10 | + buttonValue = radioSelection.value; |
| 11 | + console.log(button.value); |
| 12 | + |
| 13 | + let actions = { |
| 14 | + "Google": "https://www.google.com", |
| 15 | + "DuckDuckGo": "https://duckduckgo.com/", |
| 16 | + "Bing": "https://www.bing.com/search", |
| 17 | + "Ask": "https://www.ask.com/web" |
| 18 | + }; |
| 19 | + |
| 20 | + |
| 21 | + document.getElementById("searchForm").setAttribute = actionURL; |
| 22 | + console.log(actions[buttonValue]); |
| 23 | + event.preventDefault(); |
| 24 | + } |
| 25 | + |
6 | 26 | // TODO: create a handler
|
7 | 27 | window.addEventListener("load", function(){
|
8 | 28 | // TODO: register the handler
|
| 29 | + let form = document.querySelector("form"); |
| 30 | + form.addEventListener("submit", setSearchEngine); |
9 | 31 | });
|
10 | 32 | </script>
|
11 | 33 | </head>
|
|
14 | 36 |
|
15 | 37 | <form id="searchForm">
|
16 | 38 | <!-- TODO: add form elements -->
|
17 |
| - </form> |
| 39 | + <input type="text" name="q"><text> |
| 40 | + <label1><input type="radio" name="engine" value="Google">Google</label1> |
| 41 | + <label1><input type="radio" name="engine" value="DuckDuckGo">DuckDuckGo</label1> |
| 42 | + <label1><input type="radio" name="engine" value="Bing">Bing</label1> |
| 43 | + <label1><input type="radio" name="engine" value="Ask">Ask</label1> |
| 44 | + <button type="submit">Go!</button> |
| 45 | + </form> |
18 | 46 |
|
19 | 47 | </body>
|
0 commit comments