Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
193
rated 0 times [  194] [ 1]  / answers: 1 / hits: 18784  / 15 Years ago, sun, february 28, 2010, 12:00:00

I have a list like this:



<select name=select_list_name id=list_id>
<option value=>Select Option</option>
<option value=value1>Option 1</option>
<option value=value2>Option 2</option>
...
...
</select>


I am trying to get the text value of the currently selected option in a select list. I looked at this thread: jQuery get specific option tag text
and tried this:



$(#list_id option:selected).text()


But this only gets me the first options text (Select Option) regardless of which option has been selected.



I tried another way:



$([name=select_list_name] option:selected).text()


That gets me the first option's text concatenated with the selected options's text (Select OptionOption 2 if I select Option 2).



Any idea on why?


More From » jquery

 Answers
7

$('#list_id :selected').text(); should give you the selected option's text.



Something else in your code must be wrong -- this piece of code really works


[#97464] Thursday, February 25, 2010, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
virginia

Total Points: 632
Total Questions: 95
Total Answers: 95

Location: China
Member since Mon, Aug 22, 2022
2 Years ago
;