SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2006
    Posts
    169
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    W3C error generated on script

    Hi. I have a page that has the following script embedded in the HTML body.

    Code:
    <script language="javascript" type="text/javascript">
    document.write('<a href="javascript:popupWindow(\'http://www.hitchsource.com/licenseplateholder-pi-27157.html\')"><img src="product_thumb.php?img=images/CU_31002.jpg&amp;w=100&amp;h=78" width="100" height="78" hspace="5" vspace="5" border="0" alt="License Plate Holder" title="License Plate Holder"><br>+Click to zoom</a>'); 
    </script>
    When I run the W3C code validator on the page, I get the following error message:

    The Validator found an end tag for the above element, but that element is not currently open.

    The message is referring to the </a> tag. How do I fix the problem with this script?

    Thanks in advance!

  2. #2
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it sometime depends on the DOCTYPE you are using.

    if it is xHTML then your <img> and <br> tag should close up like <img /> and <br />

    Just try putting slashes and hope it works.

    also avoid using language="javascript" as it is now deprecated.
    Last edited by haxanstudios; Nov 11, 2007 at 20:34. Reason: add a line

  3. #3
    SitePoint Zealot
    Join Date
    Jan 2006
    Posts
    169
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi. My doctype is "HTML 4.01 Transitional" and I have a lot of other tags that are closed like </tag> versus <tag /> without errors.

    Also, I have a lot of other scripts with that have language="javascript". I've removed it, but that was not the problem, either.

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,803
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Escape the slashes in the javaScript (particularly those at the start of tags)

    <\/ instead of </
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You cannot have the character sequence '</' inside a script element, not even embedded in a string.

    The way the script element type is defined in the HTML DTDs, the ETAGO delimiter (</) followed by a name start character will be interpreted as a </script> end tag.

    As Stephen said, you need to escape this character sequence by inserting a backslash character between the '<' and the '/'.
    Birnam wood is come to Dunsinane

  6. #6
    SitePoint Zealot
    Join Date
    Jan 2006
    Posts
    169
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perfect. That took care of the problem. Thanks!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •