SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Feb 2002
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    xhtml validation and javascript

    hey all,

    i have some ampersands and less than and greater than signs in some javascrpt i wrote that the xhtml (transitional) dtd is not wanting to validate. i've tried the ISO entities, and it works, but then the javascript doesn't work. i hope there is a solution to this problem.

    example:

    function artPrevious() {
    if (document.images && thisPic > 1) {
    thisPic--
    document.myPicture.src=myArt[thisPic]
    }
    }

    thanks.

  2. #2
    SitePoint Guru nagrom's Avatar
    Join Date
    Jul 2001
    Location
    Western CT, USA
    Posts
    803
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    in XHMTL, you have to wrap your scripts like this:

    <script language="Javascript">
    <![CDATA[
    code
    ]]>
    </script>

    the CDATA tag keeps the XML borwser from tripping up on the > < and other special characters.
    beware, old browsers won't be able to read it.

    the better answer is to put your javascripts in external files. your pages will load faster too, external files are cached by the browser.

  3. #3
    What? Maelstrom's Avatar
    Join Date
    Oct 2001
    Location
    Whistler BC originally from Guelph Ontario
    Posts
    2,175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by nagrom
    in XHMTL, you have to wrap your scripts like this:

    <script language="Javascript">
    <![CDATA[
    code
    ]]>
    </script>

    the CDATA tag keeps the XML borwser from tripping up on the > < and other special characters.
    beware, old browsers won't be able to read it.

    the better answer is to put your javascripts in external files. your pages will load faster too, external files are cached by the browser.
    Well kick me in the butt I never knew. (the cdata part)...You learn something new everyday.
    Maelstrom Personal - Apparition Visions
    Development - PhP || Mysql || Zend || Devshed
    Unix - FreeBSD || FreeBsdForums || Man Pages
    They made me a sitepoint Mentor - Feel free to PM me or Email me and I will see if I can help.


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
  •