Re: document.write causes validation to fail (FAQ #1)

You need to escape the </s in your quoted text strings, or else
the validator will (rightly) think you're at the end of the 
script.  This is the most common question about javascript and
validation; see the list archives for more details.  It's not a
bug in the validator.

--Kynn

At 10:06 AM 10/14/1999 -0400, pdf@bizfon.com wrote:
>
>I've seen similar posts on this, but I haven't found a conformation that
>this is a bug in the validator.  I'm working on a page that has a bunch of
>Javascript and one of the functions includes this:
>
>     HelpWindow =
>window.open('','helpWin','width=200,height=150,left='+(screen.width-225)+',
>top=95,toolbar=no,location=no');
>     HelpWindow.focus();
>
>HelpWindow.document.write("<HTML>\n<HEAD><TITLE>Description</TITLE></HEAD>\
>n<BODY BGCOLOR='WHITE'>\n<P><B>");
>
>     HelpWindowState = "test";
>
>     HelpWindow.document.write(HelpWindowState);
>     HelpWindow.document.write("</B>\n</BODY>\n</HTML>");
>     HelpWindow.document.close();
>
>For some reason, the validation doesn't seem to realize that this HTML code
> is being generated, because it complains about the stuff inside the
>document.write parenthesis.
>This seems like a bug with the validator.  Am I wrong?  This code works,
>but because of this error, I can't tell if the rest of my document would
>pass the validation (it thinks that the HTML elements in the document.write
>parenthesis are for the document I'm working on, which throws the rest of
>them out of whack... at least for the validator).  I'm using:
><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
>
>
>
>Here's the complete list of errors:
>
>Error at line 84:
>   L>\n<HEAD><TITLE>Description</TITLE></HEAD>\n<BODY BGCOLOR='
>                                              end tag for element "TITLE"
>                                        which is not open (explanation...)
>---------------------------------------------------------------------------
>-----
>
>Error at line 84:
>   te("<HTML>\n<HEAD><TITLE>Description</TITLE></HEAD>\n<BODY BGCOLOR='WH
>                                                             end tag for
>"SCRIPT" omitted,
>          but its declaration does not permit this (explanation...)
>---------------------------------------------------------------------------
>-----
>
>Error at line 21:
>   <script language="JavaScript" type="text/javascript">
>    start tag was here
>---------------------------------------------------------------------------
>-----
>
>Error at line 84:
>   >Description</TITLE></HEAD>\n<BODY BGCOLOR='WHITE'>\n<P><B>");
>           document type does not allow element "BODY" here
>---------------------------------------------------------------------------
>-----
>
>Error at line 102:
>     HelpWindow.document.write("</B>\n</BODY>\n</HTML>");
>                 character data is not allowed here
>---------------------------------------------------------------------------
>-----
>
>Error at line 184:
>   </script>
>           end tag for element "SCRIPT" which is not open (explanation...)
>---------------------------------------------------------------------------
>-----
>
>Error at line 186:
>   </HEAD>
>         end tag for element "HEAD" which is not open (explanation...)
>---------------------------------------------------------------------------
>-----
>
>Error at line 188:
>   <BODY onload="Javascript:onPageLoad();">
>                                          document type
>                              does not allow element "BODY" here
>---------------------------------------------------------------------------
>-----
>
>Error at line 305:
>   </HTML>
>         end tag for element "HTML" which is not open (explanation...)
>
>
>
>
--
Kynn Bartlett  <kynn@idyllmtn.com>                   http://www.kynn.com/
Chief Technologist, Idyll Mountain Internet      http://www.idyllmtn.com/
Catch the web accessibility meme!                   http://aware.hwg.org/

Received on Thursday, 14 October 1999 10:43:33 UTC