Forum Moderators: open

Message Too Old, No Replies

Validation error

Why does this javascript throw a validation error

         

Beans

12:17 pm on Mar 10, 2005 (gmt 0)

10+ Year Member



Hi All
I've got a snippet of javascript here that is throwing a validation error at . . .
[validator.w3.org...]

end tag for element "STRONG" which is not open
test='<strong>text</strong>';

It seems really strange to me as I wouldn't have expected the javascript to be validated for closing html tags anyway. I know I can tweak this so the validator misses it, but for instance . . .
test='<strong>text</'+'strong>';
. . . but was wondering if anyone knew WHY it was happening. Thanks in advance for any suggestions. I'll post the snippet of code below . . .

Vince

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Title</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
</head>
<body>
<script language="javascript" type="text/javascript">
test='<strong>text</strong>';
</script>
</body></html>

BlobFisk

12:23 pm on Mar 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Beans,

Sometimes the validator gets it wrong! Some of us have a hard time accepting that, but it's the harsh reality! ;)

What I find interesting is that the validator didn't complain about your DTD or the deprecated language attribute on:

<script language="javascript" type="text/javascript">

I wonder if this may be throwing it slightly...

tedster

12:36 pm on Mar 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Because that is HTML mark-up within a script element, the recommendation is to escape the slash of any closing HTML element. So, this will validate:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Title</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
</head>
<body>
<script language="javascript" type="text/javascript">
test='<strong>text<\/strong>';
</script>
</body></html>

Here's a reference from the WDG on the topic:
[htmlhelp.com...]

It's an easy fix, and one well worth doing, IMO. Hey - if a dedicated SGML parser throws an error on it, who knows how a search engine spider will handle the same thing.

Beans

3:24 pm on Mar 10, 2005 (gmt 0)

10+ Year Member



Thanks to both of you for the superb answers.

Vince