[thelist] [DOM] Dynamically adding an OPTION to SELECT - funky IE vs Gecko...
Kasimir K
mail at kasimir-k.fi
Tue Mar 16 01:46:52 CST 2004
Helloh,
instead of:
newSelect.add(option, i);
use:
newSelect.appendChild(option);
then instead of this :
option.text = arrayOptions[1][i];
you may also want to use:
option.appendChild(document.createTextNode(arrayOptions[1][i]));
cheers,
.kasimir
...
> So there are 3 cases:
>
> newSelect.add(option); // Works in IE, but not Gecko
> newSelect.add(option, null); // Works in Gecko, but not IE
> newSelect.add(option, i); // Works in IE< but not Gecko
>
> The question is, how to get it to work in both? Any suggestions?
>
> Here is the function. Note the supplied parameter is a
> two-dimensional array for the TEXT and VALUEs of the OPTION.
>
> function BuildSelect(arrayOptions)
> {
> var arrayLength = arrayOptions[0].length;
> var oForm = document.forms['baseballForm'];
> var newSelect = document.createElement("SELECT");
> newSelect.className = "ourSelect";
>
> for(var i=0; i<arrayLength; i++)
> {
> option = document.createElement("OPTION");
> option.value = arrayOptions[0][i];
> option.text = arrayOptions[1][i];
> newSelect.add(option, i);
> }
> oForm.appendChild(newSelect);
> }
More information about the thelist
mailing list