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