SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Feb 2006
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    xhtml validation

    Hi,

    How do you get JS to validate?
    Am more or less positive my JS used to validate now the following won't even pass
    Code:
    if(1==1 && 2==2)
    {
    
    }
    why? because the validator wants &&

    Any ideas how even that script can be validated.
    The doc type is transitional.

    Best Regards
    p_h_p

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Stick all your javascript into an external document. It will be ignored.


  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,862
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    If you do place JavaScript inside an XHTML page then it must be insiide a CDATA tag so that the validator knows that it isn't HTML.

    Code:
    <script type="text/javascript"><![CDATA[
    // JavaScript goes here.
    ]]></script>
    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="^$">

  4. #4
    SitePoint Addict
    Join Date
    Feb 2006
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    in a separate folder worked a treat. That'll be why my other sites have validated and this one never, silly mistake.

    Thanks

  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)
    Quote Originally Posted by felgall View Post
    If you do place JavaScript inside an XHTML page then it must be insiide a CDATA tag so that the validator knows that it isn't HTML.
    Either that, or you must escape every '<' and '&' character as &lt; and &amp;. But then it won't work if you serve it as HTML, which is the case for 99.9999&#37; of all 'XHTML' pages.

    External JavaScript is definitely the best choice.
    Birnam wood is come to Dunsinane


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
  •