I have a drop down that has an 'ID, Name' Pair.
Example
Jon Miller
Jim Smith
Jen Morsin
Jon MIller has ID of 101
Jim Smith has ID of 102
Jen Morsin has ID of 103
When I do the followng:
var arNames = $('#Crd').val()
and I select Jon Miller, I get 101. I'd like to get Jon Miller though.
The value of the selected element can be found by using the value property on the selected element that defines the list. This property returns a string representing the value attribute of the <option> element in the list. If no option is selected then nothing will be returned.
$var = jQuery("#dropdownid option:selected"). val(); alert ($var); Or to get the text of the option, use text() : $var = jQuery("#dropdownid option:selected").
Syntax of jQuery Select Option$(“selector option: selected”); The jQuery select option is used to display selected content in the option tag. text syntax is below: var variableValue = $(“selector option: selected”).
With jQuery, you can use the . val() method to get an array of the selected values on a multi-select dropdown list.
$('#Crd').val()
will give you the selected value of the drop down element. Use this to get the selected options text.
$('#Crd option:selected').text();
The best way is to use:
$("#yourid option:selected").text();
Depending on the requirement, you could also use this way:
var v = $("#yourid").val(); $("#yourid option[value="+v+"]").text()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With