Results 1 to 5 of 5

Thread: Javascript fails the W3C HTML Validation

  1. #1
    Join Date
    Mar 2008

    Post Javascript fails the W3C HTML Validation

    I have this javascript code that I wrote and I can't figure out why every time i try to validate my website using the W3C validation it fails on the less than sign in the for loop thinking that it is the opening of a tag. Any help or idea would be greatly appreciated. Thanks.

    Here is my Javascript:

    <script type="text/javascript">
    var slideSource;
    var count = 1; <!--Count starts on 1 so that the initial slide is not repeated when moving into the slideShow function-->
    var slideArrayLength = 0;
    function setUp(){
    	var slide = new Array(); <!--Get these photos from the mySQL table for each category-->
    		slide[0] = 'images/slide.gif';
    		slide[1] = 'images/slide2.gif';
    	slideArrayLength = slide.length;
    	slideSource = new Array();
    	for(var i=0; i<slideArrayLength; i++) 
    	  slideSource[i] = new Image();
    	  slideSource[i].src = slide[i];
    	document.getElementById('slide').style.backgroundImage = "url("+slideSource[0].src+")";  <!--This is to set the initial picture to be displayed-->
    	setInterval( "slideShow()", 5000 ); <!--Repeates the slideshow over and over at X interval-->
    function slideShow(){
        document.getElementById('slide').style.backgroundImage = "url("+slideSource[count].src+")";
    	if(count >= slideArrayLength )
    		count = 0;

    Here is the W3C Error message:

    # Error Line 25, Column 32: character ";" not allowed in attribute specification list.

    for(var i=0; i<slideArrayLength; i++)

    # Error Line 25, Column 32: element "slideArrayLength" undefined.

    for(var i=0; i<slideArrayLength; i++)

    You have used the element named above in your document, but the document type you are using does not define an element of that name. This error is often caused by:

    * incorrect use of the "Strict" document type with a document that uses frames (e.g. you must use the "Frameset" document type to get the "<frameset>" element),
    * by using vendor proprietary extensions such as "<spacer>" or "<marquee>" (this is usually fixed by using CSS to achieve the desired effect instead).
    * by using upper-case tags in XHTML (in XHTML attributes and elements must be all lower-case).

    # Error Line 44, Column 8: end tag for "slideArrayLength" omitted, but OMITTAG NO was specified.


    You may have neglected to close an element, or perhaps you meant to "self-close" an element, that is, ending it with "/>" instead of ">".
    # Info Line 25, Column 15: start tag was here.

    for(var i=0; i<slideArrayLength; i++)

  2. #2
    Join Date
    May 2006
    Odenton, MD
    that is because the content is treated as PCDATA (parsed character data). that is, the validator parse the content on script tag as it where html code. in order to avoid this error, you have to comment your code as follow:

    HTML Code:
    <script type='javascript/text'>
    ... codes ...
    // ]]>
    my mom is javascript, dad is javascripter, granpa is javascriptor, and my little sister is javasRidiculous.
    my nature language is javascript, then come spanish and english -- me

  3. #3
    Join Date
    Mar 2008
    Thanks a million. I never have written javascript before this, but have come from a background in Java. Once again thanks!

  4. #4
    Join Date
    Mar 2005
    Sydney, Australia
    A better solution is to put the JavaScript in a separate file from the HTML.

  5. #5
    Join Date
    Aug 2012

    Smile Javascript Quote for W3C Validation

    You can use any of them below:

    <script type="text/javascript">
    YOUR JS CODE .........
    // -->


    <script type="text/javascript">
    YOUR JS CODE .........
    W3C will don't check your code.

    Thanks And Regards,
    Subhojit Mukherjee

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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