How to get the number of options in the dropdown list with JavaScript?

HTMLJavascriptProgramming Scripts

To get the count of options in a dropdown list, use the length property in JavaScript.

Example

You can try to run the following code to find the number of options in the drop-down −

Live Demo

<!DOCTYPE html>
<html>
<body>
<form id="myForm">
<select id="mySelect">
<option>One</option>
<option>Two</option>
<option>Three</option>
</select>
</form>
<script>
var val = document.getElementById("mySelect").length;
document.write("<br>Options in the DropDown list: "+val);
</script>
</body>
</html>
Updated on 23-Jun-2020 08:45:21