Selecting an option with javascript
- by Fibericon
I have a drop down menu that I want to have selected on page load. This is what I'm using at the moment:
var selector = document.getElementById("action_person").firstChild;
var n = 0;
while(selector.options[n] != null)
{
if(selector.options[n].value == "person")
{
selector.options.selectedIndex = n;
}
n++;
}
I've also tried replacing selector.options.selectedIndex = n with selector.options[n].selected = true. However, it never selects for me. It always shows the item at the top of the drop down.
I've verified that the value "person" does exist in the drop down, and that the variable "selector" does point to a valid drop down. What am I doing wrong here?