SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot samohtwerdna's Avatar
    Join Date
    Jul 2007
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Why wont this validate??

    Hello all,

    I am trying to get a page to validate that has a javascript print function for just printing certain content. hear is what the function looks like:

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

    <
    html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
    <
    head>
    <
    meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <
    title>mytitle</title>


    <
    script language="JavaScript" type="text/javascript">
    var 
    gAutoPrint true// Tells whether to automatically call the print function

    function printSpecial()
    {
        if (
    document.getElementById != null)
        {
            var 
    html '<HTML><head><title>CS Stucco and Plaster</title>';

            if (
    document.getElementsByTagName != null)
            {
                var 
    headTags document.getElementsByTagName("head");
                if (
    headTags.length 0)
                {
                    
    html += headTags[0].innerHTML;
                }
            }

            
    html += '\n</head>\n<body>\n';
            var 
    printReadyElem document.getElementById("printReady");

            if (
    printReadyElem != null)
            {
                
    html += printReadyElem.innerHTML;
            }
            else
            {
                
    alert("Could not find the printReady function");
                return;
            }

            
    html += '\n</body>\n</HTML>';

            var 
    printWin window.open("","printSpecial");
            
    printWin.document.open();
            
    printWin.document.write(html);
            
    printWin.document.close();
            
            if (
    gAutoPrint)
            {
                
    printWin.print();
            }
            else
            {
                
    alert("The print ready feature is only available if you are using an browser. Please update your browswer.");
            }
        }
    }
    </script> 
    and here is the validation errors I get with this setup:

    # Error Line 17, Column 20: element "HTML" undefined

    var html = '<HTML><head><title>CS Stucco and Plaster</title>';


    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 17, Column 63: character data is not allowed here

    var html = '<HTML><head><title>CS Stucco and Plaster</title>';


    Any Ideas how I can fix this??
    Finding beauty in the simple.
    Five Elephants

  2. #2
    SitePoint Evangelist elgumbo's Avatar
    Join Date
    Nov 2002
    Location
    North West, UK
    Posts
    545
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try commenting out your javascript.

    http://javascript.about.com/library/blxhtml.htm

  3. #3
    SitePoint Guru Chroniclemaster1's Avatar
    Join Date
    Jun 2007
    Location
    San Diego, CA
    Posts
    784
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It depends on the purpose of the page. This is definitely a problem with text in the script. If this is a test, then don't worry about not validating at the moment, the script won't cause problems in the production version when the script isn't inline like that.

    If this is the production version, then this is exactly the kind of errors that crop up from inline scripts. You want to yank the script out to avoid this (and many other) problems.

    Just copy the whole thing to a new file and save it with a .js extension. Delete the script tags and then insert a link tag at the bottom of the page...

    Code:
    <script type="text/javascript"  src="path/to/myScript.js"></script>
    Then you just load the events manually or call a framework function (like jQuery) to automate that for you.
    Whatever you can do or dream you can, begin it.
    Boldness has genius, power and magic in it. Begin it now.

    Chroniclemaster1, Founder of Earth Chronicle
    A Growing History of our Planet, by our Planet, for our Planet.


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
  •