<html>
<body>
<select id="mySelect">
<option>Apple</option>
<option>Orange</option>
<option>Pineapple</option>
<option>Banana</option>
</select>
<p>Click the button to select the option element with index "2".</p>
<p><b>Note:</b> The index starts at 0.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
document.getElementById("mySelect").selectedIndex = "2";
}
</script>
</body>
<!-- Mirrored from www.w3schools.com/jsref/tryit.asp?filename=tryjsref_select_selectedindex by HTTrack Website Copier/3.x [XR&CO'2014], Mon, 05 Sep 2022 15:53:13 GMT -->
</html>