
Originally Posted by
ofarah
Is there something already out there that can do it or do I have to write my own getIndxof(value)
I wish there was something like that, but there isn't. The only property directly related to 'index' is selectedIndex - which only gives you the one that's currently selected.
You won't have to write a very complicated function, though: (untested)
Code:
function selectItem(elem,val) {
var sel = document.forms[elem];
for (var i = 0, len = sel.options.length; i < len; i++) {
sel.options[i].selected = (sel.options[i].value == val);
}
}
Somewhere in your code:
selectItem('test','us');
Bookmarks