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