Return the selected option as a number
Posted: Tue Sep 20, 2005 11:00 am
I've the following code and I want to extract the return selected index to use in php code, does anyone know how to do this? Please post some tips. Thanks...
Code: Select all
<html>
<head>
<script type="text/javascript">
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="Show index of selected fruit">
<?php
echo "what is the selected index? =";
?>
</form>
</body>
</html>