alkhader alkhader - 1 month ago 4
Javascript Question

Get the option value in select in javascript


Possible Duplicate:

How to get the selected value of dropdownlist using JavaScript?

How to get the value of a selected text in javascript




<select id="short_code">
<option value="12">First</option>
<option value="11">Second</option>
<option value="10">Third</option>
<option value="9">Fourth</option>
</select>


I need to do this:

if(document.getElementById("short_code").options.item(document.getElementById("short_code").selectedIndex).text)== "First")

//get the value of the option Fist , how to get the value?

Answer
var elem = document.getElementById("short_code"),
    selectedNode = elem.options[elem.selectedIndex];

if ( selectedNode.value === "First" ) { //...