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