JavaScript - get length of list options

i did this Using JQuery

$(document).ready(function() {
    $("button").click(function(){
      var optionLength = $("#user option").length;
      
           alert("length of options is : "+optionLength);
    });
});
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>Get length of list Options</title>
</head>
  <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>

<body>
<select id="user" multiple="" size="5" class="form-control" id="participants" name="participants" style="height: 98px !important;">
  <option value="1">S RAJ</option>
  <option value="2"> SHARMA</option>
  <option value="3">SINGH</option>
  <option value="4"> ROY</option>
  <option value="5">VERMA</option>
  <select>
    <button type="button">Get Users</button>
</body>
</html>

Since you didn't specify that you could use jQuery, try this:

HTML:

<select id="test">
  <option>1</option>
  <option>2</option>
  <option>3</option>
  <option>4</option>
</select>​

JavaScript:

​document.getElementById("test").options.length

example


Select the options from the select input, then count them with length

$("#input1 option").length