Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

XHTML strict page problem with javascript

Options
  • 15-12-2005 7:52pm
    #1
    Registered Users Posts: 7,429 ✭✭✭


    Hi

    I am create a webpage which uses cookies. It has to be DTD XHTML strict.

    The code is working fine but getting warnings with it.

    The code I have is

    if (document.cookie && document.cookie != "")
    {
    process_cookie()
    }

    But i get the following warning



    Below is a list of the warning message(s) produced when validating your document.

    Warning Line 32 column 21: character "&" is the first character of a delimiter but occurred as data.
    if (document.cookie && document.cookie != "")
    This message may appear in several cases:

    You tried to include the "<" character in your page: you should escape it as "<"
    You used an unescaped ampersand "&": this may be valid in some contexts, but it is recommended to use "&", which is always safe.
    Another possibility is that you forgot to close quotes in a previous tag.



    Warning Line 32 column 22: character "&" is the first character of a delimiter but occurred as data.
    if (document.cookie && document.cookie != "")


    Do I need a meta tag that will allow me get around this problem.

    I know the & is what you would normally use for an & in html but I am doing this in javascript so I didn't think it would be a problem.

    Advise would be most helpful

    Thank


Comments

  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    Are you inserting the escape tags (<!-- and --> ) inside the <script> tags?


  • Registered Users Posts: 7,429 ✭✭✭Trampas


    seamus wrote:
    Are you inserting the escape tags (<!-- and --> ) inside the <script> tags?

    Sorry I am not sure exactly what you mean. Here is my javascript

    if (document.cookie && document.cookie != "")
    {
    process_cookie()
    }

    function process_cookie()
    {
    var whole_cookie = unescape(document.cookie);
    var drop_name = whole_cookie.split("=");
    if (drop_name[1] != "")
    {
    item_number = drop_name[1].split("xxx");
    }//ends IF
    }//ends process_cookie() function

    The code is working fine is just the area in red that is giving me warnings when i validate the code against the W3C website


  • Registered Users Posts: 7,429 ✭✭✭Trampas


    I using the <!-- and --> the W3C validates it no problem but the browser falls over as it doesn't execute any of the javascript


  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    Sorry, I was thinking of something else.... :o


  • Registered Users Posts: 6,306 ✭✭✭OfflerCrocGod


    Trampas wrote:
    The code is working fine is just the area in red that is giving me warnings when i validate the code against the W3C website
    Trampas wrote:
    I using the <!-- and --> the W3C validates it no problem but the browser falls over as it doesn't execute any of the javascript
    Make up your mind :confused: I thought your problem was what seamus said btw, but you appear to contradict yourself....


  • Advertisement
  • Registered Users Posts: 7,429 ✭✭✭Trampas


    When I put the orginal code in with the && the code executes fine. Program runs with no problems.

    It is that I have to validate it against the W3C website for XHTML Stricit DTD and it gives me a warning.

    It doesn't like the && cause it thinks that it should appear as & and not &

    So I have swapped it for the <!-- and --> which it gives me not warnings but the browser IE6 and firefox don't execute the javascript cause it doesn't like the <!-- and -->


  • Registered Users Posts: 3,886 ✭✭✭cgarvey


    You need to look up the use of CDATA for xhtml strict.. basically telling the validator/browser that the enclosed javscript isn't part of the XML dom, it's just raw text which the browser will later interpret.

    .cg


  • Registered Users Posts: 7,429 ✭✭✭Trampas


    cheers mate thats the one.


Advertisement