PDA

View Full Version : W3 XHTML+Javascript validation


PowerMacX
2005.06.27, 02:54 PM
I'm getting the following validation error using the xhtml validator at http://validator.w3.org/
#

Line 21, column 27: character ";" not allowed in attribute specification list

for (i=0;i<divList.length;i++)


#

Line 21, column 27: element "divList.length" undefined

for (i=0;i<divList.length;i++)

You have used the element named above in your document, but the document type you are using does not define an element of that name. This error is often caused by incorrect use of the "Strict" document type with a document that uses frames (e.g. you must use the "Frameset" document type to get the "<frameset>" element), or by using vendor proprietary extensions such as "<spacer>" or "<marquee>" (this is usually fixed by using CSS to achieve the desired effect instead).


#

Line 27, column 8: end tag for "divList.length" omitted, but OMITTAG NO was specified

</script>

You may have neglected to close a tag, or perhaps you meant to "self-close" a tag; that is, ending it with "/>" instead of ">".


#

Line 21, column 12: start tag was here

for (i=0;i<divList.length;i++)

Basically, I have a simple javascript that looks like this:
<script>
function something() {
var divList = document.getElementsByTagName("div");
...
for (i=0;i<divList.length;i++)
...
}
</script>

The validator is complaining about the "<" used in the for loop, but swapping it for a &lt; doesn't work, and it shouldn't even be necesary to begin with.

Anyone knows of a workaround? It is the only non-validating bit on that particular page :mad: :cry:

Edit: I'm using XHTML Transitional
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

OneSadCookie
2005.06.27, 05:20 PM
< on its own is not valid XML. &lt; would be appropriate. I don't know why that doesn't work though.

Wevah
2005.06.28, 02:48 AM
Try wrapping the script tag contents in <![CDATA[ ... ]]>, or just use an external JS file. The problem is that the validator is interpreting the < as the start of a tag; it knows nothing about JavaScript.

PowerMacX
2005.06.28, 11:15 PM
Try wrapping the script tag contents in <![CDATA[ ... ]]>, or just use an external JS file. The problem is that the validator is interpreting the < as the start of a tag; it knows nothing about JavaScript.

Thanks - I just found this page [http://www.w3.org/TR/xhtml1/diffs.html] which mentions that, so I'll do some tests tomorrow (the problem I have with external JS files is that Firefox likes to cache them, and later refuses to download updated versions when I make changes :mad: )

Perhaps &lt; works on Strict mode?
[Starts planning more tests...]

Wevah
2005.06.29, 03:54 AM
Force reload?

And no, I don't think &lt; will work, because the JS parser doesn't know (X)HTML. But you never know unless you try.

PowerMacX
2005.06.29, 10:25 AM
Force reload?

And no, I don't think &lt; will work, because the JS parser doesn't know (X)HTML. But you never know unless you try.

No, force reload doesn't force the reload of Javascripts in Firefox, the only thing that seems to work is emptying the cache.
I just tried Strict mode: lots of new validation problems... I'll stick with Transitional for a while. Now I need to test the CDATA on older browsers, otherwise the separate JS file seems like the best choice, although the aggressive caching behavior of some browsers like Firefox and some versions of IE will definitely cause troubles if I need to update the scripts.