Friday, November 23, 2012

Option Index


 <!DOCTYPE html>
<html>
<head>
<script>
function getIndex()
{
var x=document.getElementById("mySelect");
alert(x.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="Alert index of selected option">
</form>

</body>
</html>

OUTPUT:

Select your favorite fruit: 




0 comments:

Post a Comment

Thanks For Coming The Page.