Abdul Majeed
Abdul Majeed

Reputation: 2781

How to get order of selected value of a dropdown in jquery?

<select id="myselect">
<option value="10">Mr</option>
<option value="20">Mrs</option>
<option value="30">Ms</option>
<option value="40" selected>Dr</option>
<option value="50">Prof</option>
</select>

I need to get the order of selected option which is 4 if initial value is 1.

Upvotes: 0

Views: 850

Answers (2)

Milind Anantwar
Milind Anantwar

Reputation: 82241

You can use .index()

$('option').index(':selected'); //will return 3 as index is 0 based property

Upvotes: 0

Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

Reputation: 67207

Try to use .index() function to trace its order,

$("#myselect option:selected").index() + 1 
// index() will return a 0 based index so added a 1 to it.

Upvotes: 1

Related Questions