Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

XHTML strict page problem with javascript

  • 15-12-2005 07:52PM
    #1
    Registered Users, Registered Users 2 Posts: 8,639 ✭✭✭


    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, Registered Users 2 Posts: 68,173 ✭✭✭✭seamus


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


  • Registered Users, Registered Users 2 Posts: 8,639 ✭✭✭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, Registered Users 2 Posts: 8,639 ✭✭✭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, Registered Users 2 Posts: 68,173 ✭✭✭✭seamus


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


  • Registered Users, Registered Users 2 Posts: 6,344 ✭✭✭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, Registered Users 2 Posts: 8,639 ✭✭✭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, Registered Users 2 Posts: 3,890 ✭✭✭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, Registered Users 2 Posts: 8,639 ✭✭✭Trampas


    cheers mate thats the one.


Advertisement