/ Published in: JavaScript
Expand |
Embed | Plain Text
<form name=form0> <select name="selectFormName" onchange=getValueSelected()> <option value="Test A">Test A</option> <option value="Test B">Test B</option> <option value="Test C">Test C</option> </select> </form> <br/><br/> <script> function getValueSelected(){ var x = document.form0.selectFormName.selectedIndex; alert(document.form0.selectFormName.options[x].value); }; </script
Comments
Subscribe to comments
You need to login to post a comment.

I think, the version below is shorter and you can use it global on all select elements:
function getValueSelected(obj){ alert(obj.options[obj.selectedIndex].value); };
f... comment function :D
<form name=form0> <select name="selectFormName" onchange=getValueSelected(this)> <option value="Test A">Test A</option> <option value="Test B">Test B</option> <option value="Test C">Test C</option> </select> </form> <br/><br/>
<script> function getValueSelected(obj){ alert(obj.options[obj.selectedIndex].value); }; </script>