Return the number of visible options in a drop-down list:
var x = document.getElementById("mySelect").size;
Click the button to return the number of visible options in the dropdown list.
<!DOCTYPE html> <html> <body> <select id="mySelect" size="5"> <option>CSS</option> <option>Java</option> <option>HTML</option> <option>SQL</option> <option>Mouse</option> <option>Fish</option> <option>Cow</option> </select>//w w w . j a va 2s . c o m <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { var x = document.getElementById("mySelect").size; document.getElementById("demo").innerHTML = x; } </script> </body> </html>