File tree Expand file tree Collapse file tree 1 file changed +21
-3
lines changed
user-input-with-forms/studio Expand file tree Collapse file tree 1 file changed +21
-3
lines changed Original file line number Diff line number Diff line change 3
3
< head >
4
4
< meta charset ="utf-8 ">
5
5
< script >
6
- // TODO: create a handler
6
+ function setSearchEngine ( ) {
7
+ let actions = {
8
+ "google" : "https://www.google.com/" ,
9
+ "duckDuckGo" : "https://duckduckgo.com/" ,
10
+ "bing" : "https://www.bing.com/search" ,
11
+ "ask" : "https://www.ask.com/web"
12
+ }
13
+ const form = document . getElementById ( 'searchForm' )
14
+ let selectedEngine = document . querySelector ( "input[name=engine]:checked" ) ;
15
+ let action = actions [ selectedEngine . value ] ;
16
+ form . action = action ;
17
+ }
7
18
window . addEventListener ( "load" , function ( ) {
8
- // TODO: register the handler
19
+ const form = document . getElementById ( "searchForm" ) ;
20
+ form . addEventListener ( "submit" , setSearchEngine ) ;
9
21
} ) ;
10
22
</ script >
11
23
</ head >
12
24
13
25
< body >
14
26
15
27
< form id ="searchForm ">
16
- <!-- TODO: add form elements -->
28
+ < input type ="text " id ="q " name ="q "/>
29
+ < label > < input type ="radio " name ="engine " value ="google "/> Google</ label >
30
+ < label > < input type ="radio " name ="engine " value ="duckDuckGo "/> DuckDuckGo</ label >
31
+ < label > < input type ="radio " name ="engine " value ="bing "/> Bing</ label >
32
+ < label > < input type ="radio " name ="engine " value ="ask "/> Ask</ label >
33
+ < button type ="submit " value ="GO! "> GO!</ button >
34
+
17
35
</ form >
18
36
19
37
</ body >
You can’t perform that action at this time.
0 commit comments