javascript tutorial - [Solved-5 Solutions] Get selected text from a drop down list - javascript - java script - javascript array



Problem:

How can we get a drop-down list selected text in jQuery, not using the selected value?

Solution 1:

	$("#yourdropdownid option:selected").text();
click below button to copy the code. By JavaScript tutorial team

Solution 2:

Try this:

$("#myselect :selected").text();
click below button to copy the code. By JavaScript tutorial team

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

$("[id*='MyDropDownId'] :selected")
click below button to copy the code. By JavaScript tutorial team

Solution 3:

The answers posted here, for example,

$('#yourdropdownid option:selected').text();
click below button to copy the code. By JavaScript tutorial team

didn't work for me, but this did:

$('#yourdropdownid').find('option:selected').text();
click below button to copy the code. By JavaScript tutorial team

It is possibly an older version of jQuery.

Solution 4:

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

$("option:selected", myVar).text()
click below button to copy the code. By JavaScript tutorial team

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

Solution 5:

$("option:selected", $("#TipoRecorde")).text()
click below button to copy the code. By JavaScript tutorial team

Related Searches to javascript tutorial - Get selected text from a drop down list