Thomas 'PointedEars' Lahn said the following on 5/22/2006 12:21 PM:[color=blue]
> Dylan Parry wrote:
>[color=green]
>> document.onload = addOptions;[/color]
>
> Completely proprietary, and even deprecated there (in favor of
> `window.onload'). Standards compliant would be
>
> document.body.addEventListener('load', addOptions, false);
>
> However, HTML already provides the means.[/color]
Script does as well.
[color=blue][color=green]
>> function addOptions() {
>> var select = document.getElementById("light");
>>
>> for (i = 0; i < 9; i++) {[/color]
> ^
> Undeclared identifier which due to the assignment becomes a property
> of the Global Object or breaks the script (depending on the DOM).[/color]
IFF you have an element with an ID or Name of 'i' and you are using IE.
Your pedantics get old.
[color=blue][color=green]
>> var option = document.createElement("option");
>> option.text = i+1;
>> option.value = i+1;
>> select.appendChild(option);
>> }
>> }[/color]
>
> That may be the standards compliant approach, but it is not cross-browser,
> and it is known to fail. Probably it is better to create Option elements
> (from JavaScript/JScript 1.0+), and add them to the HTMLSelectElement
> object's `options' collection:
>[/color]
No DTD, invalid HTML follows.
[color=blue]
> <head>
> ...[/color]
I suppose you added the ... so you couldn't be bothered with creating a
title element that is required in any valid HTML document?
<snipped nonsense useless code>
--
Randy
comp.lang.javascript FAQ -
http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices -
http://www.JavascriptToolbox.com/bestpractices/