alkhader alkhader - 1 year ago 89
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>

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 Source
var elem = document.getElementById("short_code"),
    selectedNode = elem.options[elem.selectedIndex];

if ( selectedNode.value === "First" ) { //...
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download