Re: Error Message Feedback

On Mon, 19 Dec 2005, Peter Yuen wrote:

> I encounter some difficulties to resolve the errors in my code after HTML 4.01
> validation. The errors include the embedded Javascript in HTML at
> http://www.eurotempest.com/index_.html as follows:

Actually, the embedded JavaScript is not an issue here (though it is 
generally an issue - embedded JavaScript considered risky).

> 1. Error Line 182 column 15: document type does not allow element "MAP" here.
> <map name="map">

That's because you have the end tags </body> and </html> on lines 179 and 
180. No markup and no content (except white space) is allowed after 
them. They should appear at the very end of the document (or be omitted, 
though using explicit end tags is good style).

> 2. Error Line 464 column 30: document type does not allow element "SCRIPT" here.
> <SCRIPT type="text/javascript">

That's of course a consequence of the same error. The long <map> element 
ends at line 462, and the next element starts at 464.

The point is that _nothing_ is allowed after you have ended the <html> 
element. Maybe the validator could say this more explicitly, but I'm 
afraid that doing so might require a major rewrite of its code.

> When I move the Javascript to the beginning of HTML as recommended, it passes
> the validation but fails at Internet Explorer 6.0 with an error message
> 'document.animation' is null or not an object at my index_.html line 482.

The validator doesn't recommend any particular move. It simply says that 
the element cannot be where it now resides. Moving the <script> element
near the beginning of the document causes problems because the JavaScript 
code uses objects that have not been created yet, by the excuse for an 
HTML parser that a browser contains.

Moving the </body> and </html> tags at the end of the document should help 
with your immediate concern. A more structured approach would be to move 
all JavaScript code, except short invocations of functions in event 
attributes, into an external file referred to in a
<script src="..."></script>
construct and with the necessary initial operations invoked with <body onload="...">.

Actually you now have a <script src="...">...</script> construct, with 
nonempty content. This is not a syntax error, since a DTD cannot impose a 
restriction that the content must be empty if a particular attribute is 
present. That's however the general idea, expressed verbally:

"The script may be defined within the contents of the SCRIPT element or in 
an external file. If the src attribute is not set, user agents must 
interpret the contents of the element as the script. If the src has a URI 
value, user agents must ignore the element's contents and retrieve the 
script via the URI."
   http://www.w3.org/TR/REC-html40/interact/scripts.html#edef-SCRIPT

P.S. You sent your message to the www-validator discussion list and two 
individuals. This is probably bound to cause some confusion sooner or 
later, but I have Cc'ed the individuals.

-- 
Jukka "Yucca" Korpela, http://www.cs.tut.fi/~jkorpela/

Received on Tuesday, 20 December 2005 07:22:18 UTC