Forum Moderators: open

Message Too Old, No Replies

Javascript won't validate

         

myrrh

3:37 pm on Nov 18, 2009 (gmt 0)

10+ Year Member



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script type='text/javascript'>var a = new Array('or','f.','n@','ad','mi','mv','uu','g');document.write("<a href='mailto:"+a[3]+a[4]+a[2]+a[5]+a[6]+a[1]+a[0]+a[7]+"'>"+a[3]+a[4]+a[2]+a[5]+a[6]+a[1]+a[0]+a[7]+"</a>");</script>

Validator error: document type does not allow element "a" here

Position where error detected: the right angle bracket after the eight numerals after the mailto

Any way to fix?

Fotiman

4:49 pm on Nov 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You need to escape the / of your </a>. As in:

"<\/a>"

Otherwise, the / can be interpreted as the closing / for your <script> tag.

birdbrain

4:49 pm on Nov 18, 2009 (gmt 0)



Hi there myrrh,

validation requires the escaping of the closing a tag...

<\/a>

birdbrain

myrrh

12:13 am on Nov 24, 2009 (gmt 0)

10+ Year Member



Okay, I did that and now there are nine errors. The first error is the one I posted above. The second is:

end tag for "a" omitted, but OMITTAG NO was specified

Position where error detected: the right angle bracket after "/script"

The remainder of the errors are probably cascading errors.

Any suggestions?

daveVk

1:49 am on Nov 24, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try script tags like this

<script type="text/javascript"><!--//--><![CDATA[//><!--
...
//--><!]]></script>

see [hixie.ch...]

myrrh

2:21 am on Nov 24, 2009 (gmt 0)

10+ Year Member



That worked. Thank you all for your help.

myrrh

2:44 am on Nov 24, 2009 (gmt 0)

10+ Year Member



I spoke too soon. It validates but nothing within the script tags displays on the browsers. Did I do it wrong?

This is what I did:

<script type="text/javascript"><!--//--><![CDATA[//><!-- var a = new Array('or','f.','n@','ad','mi','mv','uu','g');document.write("<a href='mailto:"+a[3]+a[4]+a[2]+a[5]+a[6]+a[1]+a[0]+a[7]+"'>"+a[3]+a[4]+a[2]+a[5]+a[6]+a[1]+a[0]+a[7]+"<\/a>"); //--><!]]></script>

daveVk

3:01 am on Nov 24, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think it relies on there being a newline after after <!-- as // comments to end of line.

Another version (not sensitive to newlines ?) is

<script type="text/javascript">
/*<![CDATA[*/
...
/*]]>*/
</script>

myrrh

4:27 am on Nov 24, 2009 (gmt 0)

10+ Year Member



This time it did work for sure. Thank you again.