My code below works in firefox perfectly..but not in Safari. When I use the Safari debug it simply says there is a parse error, just after the first opening curly bracket {
function setVals4(class,val)
{
var array = document.getElementsByTagName("select");
for (var g = 0; g < array.length; g++)
{
sel = array[g]
//sel = document.myform.sel[g];
for (i=0; i<sel.options.length; i++)
{
//alert(sel.options[i].value)
if (sel.className == class)
{
if (sel.options[i].value == val)
{
sel.selectedIndex = i;
}
}
}
}
}
Can anyone figure out why? Help!
classis a reserved word in JavaScript, even though it isn’t used for anything (it’s listed as a “future reserved word” in the ECMA spec). If you change your parameter name toclazz(which is the usual thing) orfooor something, that should sort it out.(There’s also a missing semicolon after
sel = array[g], but that’s okay, the language allows semicolon insertion at that point. Still, best to include them, especially if you ever want to minify/pack/compress your code down-the-line.)