0

Is it possible to see what the index is of a Select combobox selection?

I have website with a select box which has a few hundred options.

<select name="breed" id="breed">
<option value="">Please select</option>
<option value="Abyssinian" >Cat: Abyssinian</option>
<option value="American Bobtail" >Cat: American Bobtail</option>
<option value="Mixed (Unknown)" >Cat: Mixed (Unknown)</option>

....

<option value="Mioritic Sheepdog" >Dog: Mioritic Sheepdog</option>
<option value="Mixed (Unknown)" >Dog: Mixed (Unknown)</option>

....

</select>

My problem is that the "Cat: Mixed (Unknown)" and the "Dog: Mixed (Unknown)" both return the same option value.

Is it possible to get the index number of the selected item?

Cheers,

Dave

3
Contributors
4
Replies
12
Views
3 Years
Discussion Span
Last Post by albucurus
0

Change the value of the option

<option value="Cat Mixed (Unknown)" >Cat: Mixed (Unknown)</option>
....
<option value="Dog Mixed (Unknown)" >Dog: Mixed (Unknown)</option>
0

Thanks Jorge, that was exactly what I was after.

@albucurus, yes, that would be the obvious thing. However, it's not my site and I'm reluctant to tinker with it.

0

You can get the index of the selected option using javascript

var index = document.getElementById("breed").selectedIndex;

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.