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