Forum Moderators: open

Message Too Old, No Replies

Validating XHTML Transitional

3 errors left and i dont know what to do

         

deadhippo

11:19 am on Jul 26, 2005 (gmt 0)

10+ Year Member



hi

ive joined a banner exchange program and the javascript they game me isnt valid xhtml
which basically means my whole site has stopped being valid
any help would be appreciated

this is the original code

<!-- Japan Banner Exchange Begin -->
<center>
<script language="JavaScript">
document.write('<s'+'cript language="JavaScript" src="http://ad.XXXX.com/work.php?n=278&size=1&j=1&code='+new Date().getTime()+'"></s'+'cript>');
</script>
<NOSCRIPT>
<IFRAME SRC="http://ad.XXXX.com/work.php?n=278&size=1" width=477 height=60 marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no"></IFRAME>
</NOSCRIPT>
</center>
<!-- Japan Banner Exchange End -->

and this is after i cleaned it up a bit

<!-- Japan Banner Exchange Begin -->
<center>
<script language="JavaScript" type="text/javascript">
document.write('<s'+'cript language="JavaScript" src="http://ad.XXXX.com/work.php?n=278&amp;size=1&amp;j=1&amp;code='+new Date().getTime()+'"></s'+'cript>');
</script>
<noscript>
<iframe src="http://ad.XXXX.com/work.php?n=278&amp;size=1" width="477" height="60" marginwidth="0" marginheight="0" frameborder="0" scrolling="no"></iframe>
</noscript>
</center>
<!-- Japan Banner Exchange End -->

but there are three errors remaining and i just dont know what to do

#Line 23, column 18: an attribute specification must start with a name or name token

document.write('<s[U]'[/U]+'cript language="JavaScript" src="http://ad.XXXX.com/work.ph

Check for stray quotes or incomplete attribute definitions.

#Line 23, column 18: document type does not allow element "s" here

document.write('<s[U]'[/U]+'cript language="JavaScript" src="http://ad.XXXX.com/work.ph

The element named above was found in a context where it is not allowed. This could mean that you have incorrectly nested elements -- such as a "style" element in the "body" section instead of inside "head" -- or two elements that overlap (which is not allowed).

One common cause for this error is the use of XHTML syntax in HTML documents. Due to HTML's rules of implicitly closed elements, this error can create cascading effects. For instance, using XHTML's "self-closing" tags for "meta" and "link" in the "head" section of a HTML document may cause the parser to infer the end of the "head" section and the beginning of the "body" section (where "link" and "meta" are not allowed; hence the reported error).

#Line 23, column 144: delimiter "'" invalid: only S separators and TAGC allowed here

...amp;code='+new Date().getTime()+'></s[U]'[/U]+'cript>');

Span

11:28 am on Jul 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



deadhippo.

if you don't put the actual JavaScript between comment tags the validator thinks it has to check that as well. Just use comment tags and your page will validate.

<script type="text/javascript">
<!--

// -->
</script>

deadhippo

11:39 am on Jul 26, 2005 (gmt 0)

10+ Year Member



wow, thanks for the fast answer
i had no idea it could be so easy
thanks a million
i should have come here hours ago
well i guess i learned a few lessons in the meantime

Hester

8:36 am on Jul 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The first error - I thought document.write didn't exist in XHTML?

The second and third errors - well, take a closer look at them. Because of the way the code is written, it looks like you have an element <s> there - the start of the script tag. Clearly the validator has a problem with that, because it doesn't know it's meant to be a script tag. So ignore those 2 errors completely.

You should also encode any ampersands in the URLs. (So "&" should be written as "&amp;".)

Also JavaScript in XHTML should be called from another file, not part of the page itself, unless there's no way round it.

deadhippo

1:04 pm on Jul 27, 2005 (gmt 0)

10+ Year Member



hi hester

do you mean that i can i can use another file and then put a link to it just like a css file
if so can you give me some pointers as this would make it much more convenient should i want to change things

thanks for the advice by the way

encyclo

5:03 pm on Jul 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The errors are happening because the validator thinks that the contents between the
<script>
tags is (X)HTML - which it isn't. So the error is in the validator, not the document. Your best bet is to place the Javascript in an external file, as Hester has suggested:

<script type="text/javascript" [b]src="/path/to/js-file.js"[/b]></script>

The document will then be parsed correctly by the validator.

I thought document.write didn't exist in XHTML?

In pure XHTML served as

application/xhtml+xml
, no,
document.write
isn't (and can't be) supported. But XHTML is almost always served as
text/html
and as such, it is merely seen by the browser as slightly broken HTML - and in HTML, you can use
document.write
with no problems. :)