SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast jester_original's Avatar
    Join Date
    Aug 2004
    Location
    devon
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript error in xhtml validator

    Hi all,
    Hope someone can help, i'm trying to validate my site in xhtml, the only page throwing an error is the index page javascript, it is part of the 'suckerfish drop down menu' i have used, it is as follows:

    <script language="javascript" type="text/javascript">
    startList = function() {
    if (document.all&&document.getElementById) {
    navRoot = document.getElementById("nav");
    for (i=0; i<navRoot.childNodes.length; i++) {
    node = navRoot.childNodes[i];
    if (node.nodeName=="LI") {
    node.onmouseover=function() {
    this.className+=" over";
    }
    node.onmouseout=function() {
    this.className=this.className.replace(" over", "");
    }
    }
    }
    }
    }
    window.onload=startList;

    function changeSrc(page){
    document.getElementById("content").src= page
    }
    </script>

    the error i get is:
    character "&" is the first character of a delimiter but occurred as data

    if (document.all&&document.getElementById) {

    i have replaced the && with the &amp; code which validates ok, but stops the nav from working.
    Any help would be greatly appreciated

  2. #2
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,426
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    You need to use CDATA comments: http://www.codehouse.com/javascript/tips/xhtml/

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

    alert("<This is compatible with XHTML>");

    //]]>
    </script>

  3. #3
    SitePoint Enthusiast jester_original's Avatar
    Join Date
    Aug 2004
    Location
    devon
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ahh! many thanks.

  4. #4
    Winemaster bronze trophy BonRouge's Avatar
    Join Date
    Oct 2004
    Location
    Sendai, Japan
    Posts
    2,417
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ...or you could put the script in an external .js file.

  5. #5
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,426
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by BonRouge
    ...or you could put the script in an external .js file.
    ...which is the better solution.


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
  •