Js gets an example of the value and number of elements in the drop down list

  • 2020-03-30 02:50:18
  • OfStack

Js gets the number of drop-down list box elements


<!DOCTYPE html>
<html>
<head>
<script>
function getLength()
{
alert(document.getElementById("mySelect").length);//Number of elements
}
</script>
</head>
<body>
<form>
<select id="mySelect">
  <option>Apple</option>
  <option>Pear</option>
  <option>Banana</option>
  <option>Orange</option>
</select>
<input type="button" onclick="getLength()" value="How many options in the list?">
</form>
</body>
</html>


Related articles: