Forum Moderators: open

Message Too Old, No Replies

formField.value='x'; for a <select>

         

okrogius

3:36 am on Mar 24, 2004 (gmt 0)

10+ Year Member



I currently have this:

var select = document.GetElementById('id');
for (var i = 0; i < select.length; i++) {
if (select.options[i].value == desiredValue) {
select.options[i].selected = true;
} else {
select.options[i].selected = false;
}
}

But it only works in IE. Firefox js console complains that select doesn't have any properties. Any ideas?

Purple Martin

5:22 am on Mar 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The first idea is that JavaScript is supposed to be case sensitive, so change "GetElementById" (which is incorrect) to "getElementById" (which is correct).

The second idea is that it's best to avoid variable names that clash with other objects - so change "select" to something safer like "mySelect".