javascript - Get selected text from a drop-down list (select box) using jQuery

ID : 308

viewed : 207

Tags : javascriptjquerydomdrop-down-menujquery-selectorsjavascript





Top 5 Answer for javascript - Get selected text from a drop-down list (select box) using jQuery

vote vote

95

$("#yourdropdownid option:selected").text(); 
vote vote

84

Try this:

$("#myselect :selected").text(); 

For an ASP.NET dropdown you can use the following selector:

$("[id*='MyDropDownId'] :selected") 
vote vote

70

The answers posted here, for example,

$('#yourdropdownid option:selected').text(); 

didn't work for me, but this did:

$('#yourdropdownid').find('option:selected').text(); 

It is possibly an older version of jQuery.

vote vote

63

If you already have the dropdownlist available in a variable, this is what works for me:

$("option:selected", myVar).text() 

The other answers on this question helped me, but ultimately the jQuery forum thread $(this + "option:selected").attr("rel") option selected is not working in IE helped the most.

Update: fixed the above link

vote vote

54

This works for me

$("#dropdownid").change(function() {     alert($(this).find("option:selected").text()); }); 

If the element created dynamically

$(document).on("change", "#dropdownid", function() {     alert($(this).find("option:selected").text()); }); 

Top 3 video Explaining javascript - Get selected text from a drop-down list (select box) using jQuery







Related QUESTION?