[ACCEPTED]-How to get text of a selected option from the select element?-jquery

Accepted answer
Score: 14

This works:

<select name="foo" id="foo">
<option value="1">a</option>
<option value="2">b</option>
<option value="3">c</option>
</select>
<input type="button" id="button" value="Button" />

$('#button').click(function() {
    alert($('#foo option:selected').text());
});

Try it yourself: http://jsfiddle.net/Nyenh/

Even simpler:

$('#foo').change(function(){
    var selected = $(this).find('option:selected');
    alert(selected.val() + ' ' + selected.text());
});

http://jsfiddle.net/qtRhQ/1/

0

Score: 1
 $("#dropdownlistID").text();

This will show all positions in your "dropdownlist". To 2 get only selected item use:

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

Or try like

 $("#foo").find(":selected").text()

instead 1 of

$("#foo option:selected").text()

More Related questions