views:

85

answers:

3

Does anyone know how to retrieve the option chosen from a drop-down select box?

I'm using document.getElementById("mySelect").value and it doesn't seem to be working...

+5  A: 
document.getElementById("mySelect").options[document.getElementById("mySelect").selectedIndex].value
Al W
A: 

Are you sure your drop-down has a value in it? Did you provide values for it?

<select id="dropdownBox">
<option value="val1">value 1</option>
<option value="val2">value 2</option>
<option value="val3">value 3</option>
<option value="val4">value 4</option>
</select>

The values are val1, val2...

Khan
A: 

It's better for code optimization to do something like:

var o = document.getElementById("mySelect");
o.options[o.selectedIndex].value;

jQuery alternative:

$("#mySelect").val();
Dimitar Ivanov