Returning selectedIndex of SELECT by giving VALUE as arg

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Returning selectedIndex of SELECT by giving VALUE as arg

Post by anjanesh »

Is there any way to do this ?

Code: Select all

<select name="sel1">
  option value="a1">a</option>
  option value="b2">b</option>
  option value="c3">c</option>
  option value="d4">d</option>
  option value="e5">e</option>
</select>
<script>
  var SelValue="d4";
  var SelIndex=(........) // Should return 3
</script>
Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you'd have to loop through the values in said select looking for it's existance.
Post Reply