How do I retrieve the zero-based index of the selected option in a select box?

Posted by Ben McCormack on Stack Overflow See other posts from Stack Overflow or by Ben McCormack
Published on 2010-04-08T18:08:38Z Indexed on 2010/04/08 18:13 UTC
Read the original article Hit count: 359

Filed under:
|
|

Let's say I have the following in my HTML code:

  <select name="Currency" id="Currency">
    <option value="0.85">Euro</option>
    <option value="110.33">Japanese Yen</option>
    <option value="1.2">Canadian Dollars</option>
  </select>

Using jQuery, I can use $("#Currency").val() to give me the selectd value, and I can use $("#Currency :selected").text() to get the selected text.

What do I need to do to get the zero-based index (in this case, 0, 1, or 2) of the current selection?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about JavaScript