Forum Moderators: open

Message Too Old, No Replies

My JavaScript won't validate

...and it's very simple

         

Emperor

12:24 am on Dec 3, 2004 (gmt 0)

10+ Year Member



Hi guys,

Is it normal for JavaScript to cause the Validator to fail?

Here it is, nice and simple, I tried a few things, like different quotes, no avail:

<script type="text/javascript">
var strOutput='<a href="http://www.msn.com">MSN</a>';
document.write(strOutput);
</script>

<noscript>
<a href="http://www.msn.com">MSN</a>
</noscript>

I'm kinda anal about my pages validating so what should I do?

Take care,
Cyrus

DrDoc

1:13 am on Dec 3, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



what does the validator say?

Emperor

1:31 am on Dec 3, 2004 (gmt 0)

10+ Year Member



It says this:

document type does not allow element "a" here

among other things

Rambo Tribble

2:34 am on Dec 3, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your noscript tag should be within the body of the document. A noscript tag is for the inclusion of content that displays when JavaScript is not enabled, and all content should be in the body. As I recall, the a tag should appear within a paragraph, division, or such, as well.

Emperor

2:46 am on Dec 3, 2004 (gmt 0)

10+ Year Member



Hi,

I have the <noscript> tag in the body (in a <div> as well) and that wasn't it.

I did get it to validate but I still get a warning. Here is what I had to do:

var strOutput="<\a href="...">Link<\/a>";
document.write(strOutput);

Notice the gay backslashes I had to use before the 'a' and the closing 'a'?

Do you think that can mess anything up when it's written? It works in IE6 and Firefox.

Take care,
Emperor

Rambo Tribble

6:03 am on Dec 3, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What you're doing is escaping the characters, and, yes, within a script you should escape your slashes because the interpreter would be within its rights to interpret the first occurrence of an unescaped forward slash as belonging by necessity to the closing script tag. Or so I'm told.

I don't think it should be required before the a, though.

kaled

9:55 am on Dec 3, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The first occurrence of </ may be regarded as terminating the script. The forward slash must be escaped using a \ character so </ becomes <\/

Kaled.