Is there a way to reference a selected item from a dropdown menu implemented using select besides by index number? For instance, I would like a javascript function that does something like:
if (document.getElementById("My_Select_Menu").selectedIndex.value == "Blue")
{
do something;
}
but selectedIndex seems to return only a reference number to the first selected item. It seems like there should be a way to reference the value of the selected item, am I missing it?
Try:
selectedIndexreturns the offset of the selected option (as an integer) so you need to use that to grab the actual element from options of the<select>.Demo.