Javascript examples for DOM HTML Element:Option
The Option object represents an HTML <option> element.
You can access an <option> element by using getElementById():
<!DOCTYPE html> <html> <body> <select> <option id="myOption" value="css">CSS</option> <option value="java">Java</option> </select>//w w w .j a v a 2s . c o m <button onclick="myFunction()">get the text of the option in the drop-down list</button> <p id="demo"></p> <script> function myFunction() { var x = document.getElementById("myOption").text; document.getElementById("demo").innerHTML = x; } </script> </body> </html>