[ACCEPTED]-How to get text of a selected option from the select element?-jquery
Accepted answer
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());
});
0
$("#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()
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.