Javascript examples for DOM HTML Element:Select
Select options Collection - Choose an option in the drop-down list and output the text of the selected option in an element with id="demo":
<!DOCTYPE html> <html> <body> <p>Choose an option in the drop-down list and display that option.</p> <form> <select id="mySelect" onchange="myFunction()"> <option>Apple</option> <option>Orange</option> <option>Pineapple</option> <option>Banana</option> </select> </form>//from w w w .ja v a 2s . c o m <p id="demo"></p> <script> function myFunction() { var x = document.getElementById("mySelect"); var i = x.selectedIndex; document.getElementById("demo").innerHTML = x.options[i].text; } </script> </body> </html>