Asim Zaidi
Asim Zaidi

Reputation: 28284

jquery selected value in drop down

I have a drop down. How do I get the selected option, not the value but innerHTML. I want CO from the example. This alert($('#mydropdown').val()); gives me the value 1 but I dont want that.

<select name='mydropdown' id='dd'>
<option value=1 selected>CO</option>
<option value=2>CA</option>

<option value=3>TX</option>

</select>

Upvotes: 2

Views: 6127

Answers (2)

John
John

Reputation: 9456

$("#dd").val();

That's all you need to do.

Upvotes: 3

user113716
user113716

Reputation: 322492

$('#dd :selected').text();

Note that using #, you're selecting by ID. The ID of your element is dd, not mydropdown.

If you were to do it with plain javascript, you would want to have your name attribute match the id attribute in order to deal with IE bugs.

<select name='dd' id='dd'>
   ...
</select>

js

var select = document.getElementById('dd')
select.options[select.selectedIndex].text;

Upvotes: 6

Related Questions