Dylan Parry wrote:
document.onload = addOptions;
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.
function addOptions() {
var select = document.getElementById("light");
for (i = 0; i < 9; i++) {
^
Undeclared identifier which due to the assignment becomes a property
of the Global Object or breaks the script (depending on the DOM).
var option = document.createElement("option");
option.text = i+1;
option.value = i+1;
select.appendChild(option);
}
}
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:
<head>
...
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
function addOptions(sForm, sSelect)
{
var select = document.forms[sForm].elements[sSelect];
for (var i = 0; i < 9; i++)
{
select.options[select.options.length] = new Option(i + 1, i + 1);
}
}
</script>
...
</head>
<body onload="addOptions('myForm', 'mySelect');">
...
</body>
PointedEars
--
There are two possibilities: Either we are alone in the
universe or we are not. Both are equally terrifying.
-- Arthur C. Clarke