<html>
<body>
<p>Do not select a fruit, just click the button. The selectedIndex property will return "-1" if no options are selected.</p>
<select id="mySelect" size="4">
<option>Apple</option>
<option>Orange</option>
<option>Pineapple</option>
<option>Banana</option>
</select>
<button type="button" onclick="myFunction()">Display index</button>
<script>
function myFunction() {
var x = document.getElementById("mySelect").selectedIndex;
alert(x);
}
</script>
</body>
<!-- Mirrored from www.w3schools.com/jsref/tryit.asp?filename=tryjsref_select_selectedindex_minus by HTTrack Website Copier/3.x [XR&CO'2014], Mon, 27 Jan 2020 03:17:49 GMT -->
</html>