HTML select on-change event JavaScript

This is an example how to get the index and selected text from a select in html:

Try it:

Code:
<script type="text/javascript">
function getOS(sel) {
    alert("Index: "+sel.selectedIndex+"  -  Value: "+sel.options[sel.selectedIndex].text);  
}
</script>

<select id="OS_SELECT" onchange="getOS(this)">
<option value="1">Linux</option>
<option value="2">Microsoft</option>
<option value="3">MAC OS X</option>
</select>

Leave a Reply

Your email address will not be published.

two × one =