Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Posts
    672
    Thanks
    1
    Thanked 1 Time in 1 Post

    Unary decrement ruins validation

    Why is it that the W3 validator always chokes up on unary decrements?

    for(i=8;i>0;i--)
    {
    }

    It mistakes it for a comment declaration whether your javascript is within HTML comment declarations or not. Is the only solution to use i-=1 or work backwards using i++? I don't see why this throws an error if it's valid scripting.

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Did you enclose the codes in CDATA block?

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

    ...

    /* ]]> */
    </script>

  • #3
    Regular Coder
    Join Date
    Nov 2002
    Posts
    672
    Thanks
    1
    Thanked 1 Time in 1 Post
    I was using the <!-- and -->. I've never seen this CDATA thing ever used in a script before. How widely known is it? I've never really commented my scripts out unless it was for sake of validation. What exactly is it and how is it interpreted? I've only seen it used in DTD files. Is this parsed by the browser or the validator?

  • #4
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    CDATA is required in XML for <, > and & to not be considered specialo characters. The only character sequence CDATA may not include, and whicdh will not be considered as raw character data, is ]]>

    It's an XML structure, unnecessary in HTML. That's the reason we place it within comments.


    As for <!-- --> not able to contain --, that is because -- was the toggle on/off comments in parser command sequences in SGML. In XML it may not be placed within parser command sequences, and must contain only a single comment.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards


  •  

    Posting Permissions

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