Javascript examples for DOM HTML Element:Select
The length property returns the number of <option> elements in a drop-down list.
A Number, representing the number of <option> elements found in the drop-down list
The following code shows how to return the number of <option> elements found in a drop-down list:
<!DOCTYPE html> <html> <body> <select id="mySelect"> <option>CSS</option> <option>HTML</option> <option>SQL</option> <option>Javascript</option> </select>//w w w . ja v a 2 s . c om <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { var x = document.getElementById("mySelect").length; document.getElementById("demo").innerHTML = x; } </script> </body> </html>