Re: [VE][79] and [VE][61] error in js section

On 17 Sep 2007, at 20:09, Kate wrote:
> One of the most frustrating things I find with the validator is that
> perfectly valid JavaScript causes errors.

Embedding one computer language inside another computer language is  
always troublesome, you have to

> Putting the JavaScript in a separate file works when the  
> information in the JavaScript is static BUT
> when the JavaScript is in part generated by the PHP code it becomes  
> a real
> problem. It is not always possible to avoid end tags in scripts as the
> reason for the JavaScript in some of my files is to output blocks  
> of HTML or
> XHTML code. The work around for this can be quite ugly with things  
> like
> "document.write('<p id="'+$newid'+'" style="color:#FF0000">' +
> $javascriptvar + '</'+'p>);"

Well...

(a) Best practise generally says "Don't use document.write", use DOM  
methods instead.
(b) I'm not aware of any current browser which supports  
document.write in XHTML mode (XHTML documents served as text/html are  
treated at HTML so don't count)
(c) The FAQ describes that situation, it is not hard to stick a "\"  
before the / in an end tag, or use CDATA markers (if you are  
insisting on using XHTML).

> I have often wondered why the validator is not ignoring all the  
> data between
> the opening <script type="text/javascript"> tag and the closing </ 
> script>
> tag?

Because the HTML and XHTML specifications require it to. The former  
because the parser has to recognise where the end of the script  
element exists (and there are a number of shorthand constructs in  
SGML which mean that </script> isn't the only thing that can end the  
tag), the latter because XML is significantly simpler then SGML and  
doesn't have any syntax in its DTDs which can say "The content of  
this element is not markup".

-- 
David Dorward
http://dorward.me.uk/
http://blog.dorward.me.uk/

Received on Tuesday, 18 September 2007 08:02:08 UTC