The length
property returns the
number of <option> elements in a drop-down list.
length |
Yes | Yes | Yes | Yes | Yes |
var v = selectObject.length
A Number type value representing the number of <option> elements found in the drop-down list.
The following code shows how to get the number of <option> elements found in a drop-down list.
<!DOCTYPE html>
<html>
<body>
<!-- w w w . ja v a2 s.com-->
<select id="mySelect">
<option>A</option>
<option>B</option>
<option>C</option>
<option>D</option>
</select>
<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>
The code above is rendered as follows: