Re: HTML 4.01 Transitional validation
- From: Thomas 'PointedEars' Lahn <PointedEars@xxxxxx>
- Date: Mon, 22 May 2006 18:21:14 +0200
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
.
- Follow-Ups:
- Re: HTML 4.01 Transitional validation
- From: Randy Webb
- Re: HTML 4.01 Transitional validation
- References:
- HTML 4.01 Transitional validation
- From: Tim L
- Re: HTML 4.01 Transitional validation
- From: Dylan Parry
- HTML 4.01 Transitional validation
- Prev by Date: Re: accessability of javascript
- Next by Date: Re: annoying javascript error
- Previous by thread: Re: HTML 4.01 Transitional validation
- Next by thread: Re: HTML 4.01 Transitional validation
- Index(es):
Relevant Pages
|
Loading