Martin Honnen schrieb:
[color=blue][color=green]
> > myNewGrandChildElement =
> > window.document.createElement(''option'');[/color]
> ^^ ^^
> That seems to be a syntax error.
> Anyway, if you want to set the selected attribute of a newly created
> option element then do e.g.
> newOption.defaultSelected = newOption.selected = true;
>
>
> --
>
> Martin Honnen
>
http://JavaScript.FAQTs.com/[/color]
Sorry, that was my mistake (I'm a newbie in this NG): The Code is
generated by PL/SQL, so I needed '' to get '.
[color=blue]
> Anyway, if you want to set the selected attribute of a newly created
> option element then do e.g.
> newOption.defaultSelected = newOption.selected = true;[/color]
Thanks Martin for your quick assistance, but defaultSelected does not
work either.
Meanwhile I have tried the following code (this time with correct
quoting):
//snip
myCurrentElement = window.document.getElementById('role');
myNewElement =
window.document.getElementsByTagName('font')[0];
myNewChildElement =
window.document.getElementsByTagName('select')[0];
for (var i = 0; i < optionArray.length; i++)
{
myNewGrandChildElement =
window.document.createElement('option');
myNewGrandChildElement.setAttribute('value',
optionArray[i]["value"]);
if (optionArray[i]["selected"]!=null)
{
//myNewGrandChildElement.setAttribute('selected', 'selected');
//myNewGrandChildElement.defaultSelected =
myNewGrandChildElement.selected = true;
myNewChildElement.selectedIndex = i;
}
myNewGrandChildElementText =
window.document.createTextNode(optionArray[i]["label"]);
myNewGrandChildElement.appendChild(myNewGrandChild ElementText);
myNewChildElement.appendChild(myNewGrandChildEleme nt);
}
myNewElement.appendChild(myNewChildElement);
myCurrentElement.appendChild(myNewElement);
window.document.close;
//snip
The funny thing is, that that Opera (V8.54) understands that code if I
replace "i" with a static number like 1, but it does not work with the
variable itself.
Regards
Reinhold