Possible Duplicate:
jQuery get selected text from dropdownlist
<select id="id_deals" name="deals" multiple="multiple">
<option value="1">deal 2</option>
<option value="2">deal 1</option>
</select>
With jquery I can get the value of the selected items like this:
var selected = $(e.target).val();
>> 2
But surprisingly when I try to get the actual selected text (e.g. deal 1), it gives me both entries:
var selected_text = $(e.target).text();
>> "\ndeal 2\ndeal 1\n"
Why is that and how could I get the text of the selected entries as well?
The jQuery "text()" method returns the inner text of the selected element. In your case you're selecting the whole select tag, so it's giving you all the text inside it (excluding the nested tags themselves). Instead, use:
$("#yourdropdownid option:selected").text();
See this: Get selected text from a drop-down list (select box) using jQuery
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