Animowane formularze JavaScript
Demonstracja zmian pól formularza w zależności od wartości w polu ComboBox (input type select)
Ctrl + Shift + K – konsola JavaScript (Firefox)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Sample</title> <script type="text/javascript"> onload = function(e) { document.forms["myForm"]["intelligenceOther"].style.display = "none"; document.forms["myForm"]["intelligence"].onchange = function (e) { e.target.form["intelligenceOther"].style.display = e.target[e.target.selectedIndex].value == "other" ? "inline" : "none"; if (e.target[e.target.selectedIndex].value == "1") document.forms["myForm"]["liczba"].value= "Opcja 1sza"; else document.forms["myForm"]["liczba"].value= "Opcja inna niż 1sza"; }; document.forms["myForm"]["intelligence"].selectedIndex = 0; } </script> </head> <body> <form id="myForm" action=""> <div> <select name="intelligence"> <option value="1" selected="selected">Dull (0-1)</option> <option value="2">Smart (1-2)</option> <option value="3">Brilliant (2-3)</option> <option value="other">Other</option> </select> <input type="text" name="intelligenceOther"> <br> <input type="text" name="liczba"> </div> </form> </body> </html> |
Show Comments