SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Feb 2004
    Location
    Norway
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript and W3C

    Hi,

    I have noticed that the W3C validator http://validator.w3.org/ complains about Javascript, such as:

    Line 97, column 38: document type does not allow element "style" here
    document.write('<style type="text/css">\n#tabcontentcontainer{display: none;}\n<

    and

    Line 120, column 34: character ";" not allowed in attribute specification list
    for (i=0; i<tabobjlinks.length; i++)

    Is there any information anywhere about how to deal with such errors?

    Regards.

  2. #2
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    Edmonton, the upper part of AB.
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anything in an xml document you don't want parsed (in your case, javascript) must be wrapped in cdata (character data) tags: <![CDATA[ ... ]]>

    Code:
    <script type="text/javascript" language="Javascript">
    <!--
    <![CDATA[
    
    /* all javascript code here */
    
    ]]>
    //-->
    </script>
    -Paul

  3. #3
    SitePoint Member
    Join Date
    Feb 2004
    Location
    Norway
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by discotraxx
    Anything in an xml document you don't want parsed (in your case, javascript) must be wrapped in cdata (character data) tags: <![CDATA[ ... ]]>

    Code:
    <script type="text/javascript" language="Javascript">
    <!--
    <![CDATA[
    
    /* all javascript code here */
    
    ]]>
    //-->
    </script>
    -Paul
    That stops the W3C validator from complaining, but it also stops my script from working. What am I missing?

  4. #4
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anything in an xml document you don't want parsed (in your case, javascript) must be wrapped in cdata (character data) tags: <![CDATA[ ... ]]>
    Anyone should be able to get html pages with javascript in them to validate--even against xhtml 1.0 Strict--without CDATA tags.

    First of all, any flagged errors depend on what standard you are validating against.

    In addition, your first example is incomplete since you cut off the html mid-line, and it certainly won't validate against any standard as posted, and the second example doesn't make sense since there is no attribute specification list in the line you posted.

    As for information on your errors, the W3C provides the standard for html 4.0, xhtml 1.0, etc. which you can check your code against to determine what's wrong. If you want someone here to help you get your page to validate, then you need to post the whole html page.
    Last edited by 7stud; Jan 15, 2005 at 22:30.

  5. #5
    SitePoint Wizard gold trophysilver trophybronze trophy dc dalton's Avatar
    Join Date
    Nov 2004
    Location
    Right behind you, watching, always watching.
    Posts
    5,431
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can also get around this by putting things such as a document.write into an external js file and linking to it

    <script type='text/javascript' src='your.js'><script>

    its not parsed by the validator ... no errors, still works


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
  •