Python-Ref > Mimo python > JavaScript > Reacting to user input
 
 

<-^^->
Klíčová slova
Moduly
Knihovní funkce

Reacting to user input

Expand/Shrink
Zdroj: (js3-1.html)
  1   <html xmlns="http://www.w3.org/1999/xhtml">
  2   <head>
  3    <title>Javascript example</title>
  4    <meta content="text/html; charset=utf-8" http-equiv="content-Type"/>
  5   </head>
  6   <body>
  7     <select onchange="alert('You selected: '+this.options[this.selectedIndex].value);">
  8       <option selected="selected" value="default">Choose a book...</option>
  9       <option value="The Hitchhiker's Guide to the Galaxy">The Hitchhiker's Guide to the Galaxy</option>
 10       <option value="So Long, and Thanks for All the Fish">So Long, and Thanks for All the Fish</option>
 11       <option value="Dirk Gently's Holistic Detective Agency">Dirk Gently's Holistic Detective Agency</option>
 12     </select>
 13   </body>
 14   </html>
Doba běhu: 2.2 ms
Expand/Shrink
function display_selection(e) {
    var selection = e.target; // e is event
    var value = selection.options[selection.selectedIndex].value;
    var book = document.getElementById('book');
    if (value != "default") {
	book.innerHTML = "<b>You selected</b>: " + value;
    }
    else
	book.innerHTML = "<b>You did not select anything!</b>";
}

Zdroj: (js3-2.html)
  1   <html xmlns="http://www.w3.org/1999/xhtml">
  2   <head>
  3    <title>Javascript example</title>
  4    <meta content="text/html; charset=utf-8" http-equiv="content-Type"/>
  5    <script src="infiles/js3-2.js" type="text/javascript"> </script>
  6   </head>
  7   <body>
  8     <select onchange="display_selection(event);">
  9       <option selected="selected" value="default">Choose a book...</option>
 10       <option value="The Hitchhiker's Guide to the Galaxy">The Hitchhiker's Guide to the Galaxy</option>
 11       <option value="So Long, and Thanks for All the Fish">So Long, and Thanks for All the Fish</option>
 12       <option value="Dirk Gently's Holistic Detective Agency">Dirk Gently's Holistic Detective Agency</option>
 13     </select>
 14     <div id="book"/>
 15   </body>
 16   </html>
Doba běhu: 1.8 ms