<!DOCTYPE html>
<html>
<head>
<script>
function getIndex() {
document.getElementById("demo").innerHTML =
document.getElementById("mySelect").selectedIndex;
}
</script>
</head>
<body>
<form>
Select your favorite fruit:
<select id="mySelect">
<option>Apple</option>
<option>Orange</option>
<option>Pineapple</option>
<option>Banana</option>
</select>
<br><br>
<input type="button" onclick="getIndex()"
value="Display the index of the selected option">
</form>
<p id="demo"></p>