Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
158
rated 0 times [  160] [ 2]  / answers: 1 / hits: 139761  / 14 Years ago, thu, september 2, 2010, 12:00:00

I have a normal dropdown which I want to get the currently selected index and put that in a variable. Jquery or javascript. Jquery perfered.



<select name=CCards>
<option value=0>Select Saved Payment Method:</option>
<option value=1846>test xxxx1234</option>
<option value=1962>test2 xxxx3456</option>
</select>

More From » jquery

 Answers
3

$(select[name='CCards'] option:selected) should do the trick



See jQuery documentation for more detail: http://api.jquery.com/selected-selector/



UPDATE:
if you need the index of the selected option, you need to use the .index() jquery method:



$(select[name='CCards'] option:selected).index()

[#95730] Monday, August 30, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cristinadomoniquel

Total Points: 320
Total Questions: 94
Total Answers: 94

Location: Moldova
Member since Sat, Aug 6, 2022
2 Years ago
cristinadomoniquel questions
Wed, Apr 7, 21, 00:00, 3 Years ago
Tue, Dec 1, 20, 00:00, 4 Years ago
Mon, Nov 23, 20, 00:00, 4 Years ago
Mon, Aug 17, 20, 00:00, 4 Years ago
;