473,387 Members | 3,801 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

HTML 4.01 Transitional validation

A newbie question:

A page including the code fragment below works - in FF - but HTML 4.01
Transitional validation tells me:
"document type does not allow element "SCRIPT" here"
<SELECT id="light" >
<SCRIPT type="text/javascript">
for (j=0;j<9;j++) {document.write("<OPTION VALUE='" + j + "'>
" + (j + 1) ) } ;
</SCRIPT>
</SELECT>

Can anyone help?

(The fragment also produced the select elements I expect in IE)


May 15 '06 #1
8 2743


Tim L wrote:
A page including the code fragment below works - in FF - but HTML 4.01
Transitional validation tells me:
"document type does not allow element "SCRIPT" here"
<SELECT id="light" >
<SCRIPT type="text/javascript">
for (j=0;j<9;j++) {document.write("<OPTION VALUE='" + j + "'>
" + (j + 1) ) } ;
</SCRIPT>
</SELECT>


You will have to document.write the complete select element including
the option elements.

--

Martin Honnen
http://JavaScript.FAQTs.com/
May 15 '06 #2
Pondering the eternal question of "Hobnobs or Rich Tea?", Tim L finally
proclaimed:

[script to add options to select element]
"document type does not allow element "SCRIPT" here"


Either do as Martin suggests, or create a Javascript function that fires
on the onload event and adds new child elements to the select element
through the DOM.

Something like:

---- start ----
document.onload = addOptions;

function addOptions() {
var select = document.getElementById("light");

for (i = 0; i < 9; i++) {
var option = document.createElement("option");
option.text = i+1;
option.value = i+1;
select.appendChild(option);
}
}
----- end -----

--
Dylan Parry
http://webpageworkshop.co.uk -- FREE Web tutorials and references
May 15 '06 #3
Dylan Parry said the following on 5/15/2006 10:05 AM:
Pondering the eternal question of "Hobnobs or Rich Tea?", Tim L finally
proclaimed:

[script to add options to select element]
"document type does not allow element "SCRIPT" here"
Either do as Martin suggests, or create a Javascript function that fires
on the onload event and adds new child elements to the select element
through the DOM.

Something like:

---- start ----
document.onload = addOptions;


Except that line should be window.onload
function addOptions() {
var select = document.getElementById("light");

for (i = 0; i < 9; i++) {
var option = document.createElement("option");
option.text = i+1;
option.value = i+1;
select.appendChild(option);
}
}


And if the browser doesn't support gEBI (unlikely) but createElement and
appendChild could lack support. Feature test :)

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 15 '06 #4
Pondering the eternal question of "Hobnobs or Rich Tea?", Randy Webb
finally proclaimed:
document.onload = addOptions;


Except that line should be window.onload


You're right, of course.
function addOptions() {
var select = document.getElementById("light");

for (i = 0; i < 9; i++) {
var option = document.createElement("option");
option.text = i+1;
option.value = i+1;
select.appendChild(option);
}
}


And if the browser doesn't support gEBI (unlikely) but createElement and
appendChild could lack support. Feature test :)


Which is of course why I said "something like" ;) I would probably not
use Javascript for creating options for a select element in the way that
the OP was obviously using it anyway. In fact for the limited number of
options that the OP is creating, it would be easier and more reliable to
simply write the option elements by hand!

--
Dylan Parry
http://electricfreedom.org -- Where the Music Progressively Rocks!
May 15 '06 #5
Thanks.

Where on line should I have been able to find that documented / explained?

Tim
"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:44***********************@newsread4.arcor-online.net...


Tim L wrote:
A page including the code fragment below works - in FF - but HTML 4.01
Transitional validation tells me:
"document type does not allow element "SCRIPT" here"
<SELECT id="light" >
<SCRIPT type="text/javascript">
for (j=0;j<9;j++) {document.write("<OPTION VALUE='" + j +
"'> " + (j + 1) ) } ;
</SCRIPT>
</SELECT>


You will have to document.write the complete select element including the
option elements.

--

Martin Honnen
http://JavaScript.FAQTs.com/

May 15 '06 #6


Tim L wrote:
Where on line should I have been able to find that documented / explained?


Well you have to look at the HTML definition and learn to read a DTD,
the select element definition in HTML 4 is here
<http://www.w3.org/TR/html4/interact/forms.html#edef-SELECT>
and says
<!ELEMENT SELECT - - (OPTGROUP|OPTION)+ -- option selector -->
meaning the allowed contents is one or more optgroup or option element.
There is also prose saying "A SELECT element must contain at least one
OPTION element.".
So the definition definitely shows that script is not allowed as a child
element of select.

--

Martin Honnen
http://JavaScript.FAQTs.com/
May 15 '06 #7
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
May 22 '06 #8
Thomas 'PointedEars' Lahn said the following on 5/22/2006 12:21 PM:
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.


Script does as well.
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).


IFF you have an element with an ID or Name of 'i' and you are using IE.
Your pedantics get old.
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:


No DTD, invalid HTML follows.
<head>
...


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/
May 22 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: R. Rajesh Jeba Anbiah | last post by:
I would like to know what HTML standard will be better for PHP webapplications? Right now, I use HTML 4.01 Transitional. And like to know what *you* PHP programmers prefer? and which is good? TIA....
12
by: StardogChampion | last post by:
I have wittled down my errors from 12 to 2, but the 2 it shows i can't really do anything about. 1. Line 126, column 48: there is no attribute "COLOR" <td height="1" colspan="5"><hr size="1"...
12
by: Marinemasters | last post by:
I used the W3C markup and validation service for http://www.wasmundbindery.com and got this reply back. I don't understand what it means or how to fix it. The DOCTYPE Declaration in your...
54
by: Howard Kaikow | last post by:
Where is the official documentation of what constitutes a minimally compliant HTML file? -- http://www.standards.com/; See Howard Kaikow's web site.
7
by: Alan Silver | last post by:
Hello, I am a complete and utter newbie at ASP.NET, so please forgive any stupid questions ;-) I am just trying to get my head around the whole web forms business, but have run into a...
3
by: danny.rendle | last post by:
I am attempting to create a web site using ASP.NET v1.1 to comply with the W3C's WAI Triple-A standard. To this end I need ASP.NET to emit valid HTML 4.01 Transitional (once confident with...
4
by: Arthur Dent | last post by:
Hello all, ive been programming with ASP.NET since it came out, but am just getting my feet with now with v.2. Ive noticed something strange in the way my HTML tables get rendered with 2. I use...
6
by: Rolf Welskes | last post by:
Hello, if I have for example: <table style="width: 100%; height: 100%;" border="1"> <tr> <td style="width: 100px">k </td> <td style="width: 100px">k </td> </tr>
1
by: Tatyana | last post by:
Hi All, I have a question regarding validation with XHTML on ASP.Net websites. Our site is built on ASP.NET 2.0 with validation XHTML. Search Engine Optimizer advised us that we should change it...
2
by: Bruno Schneider | last post by:
I've seen this page, that seems invalid to me. Doctype is incomplete and it does not have a <bodytag. However, W3C validator validates it as HTML 4.01 strict, even when I force the DOCTYPE. I think...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.