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 3 of 3
  1. #1
    New Coder
    Join Date
    Mar 2009
    Posts
    23
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Unhappy body problems (<body>)

    HI !!! 2nd thread

    I was very happy with the reply i got in the last post, it worked thankyou !!!

    now my next problem!!!

    I have been trying for the last couple of days and havent solved it yet.

    I have a cookie that stores the name of a cursor. the script writes what i need and all i have to do it get it working in the body tag

    Code:
    <script type="text/javascript" src="cookie.js">
    </script>
    
    <script type="text/javascript">
    
    var bc = "'bc'"
    
    function pgcursor() {
    	cursor=getCookie('cursor');
    	if (cursor!=null && cursor!="")
    return 'document.getElementById('+bc+').style="cursor:url('+cursor+');"'
    }
    document.write(pgcursor())
    </script>
    
    <body id="bc" name="bc" style="cursor:url();">
    basically i need to output the cookie in the cursor url part of the body tag

    and in the script i have

    Code:
    document.write(pgcursor())
    just to see if it is outputing the right things thankyou

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,155
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    Various errors:
    (1) var bc = "'bc'"
    No. Just
    var bc = "bc";
    But you shouldn't use an ID on the <BODY> tag in any case.

    (2) You are doing
    document.write(pgcursor())
    *before* the <BODY> tag! When you do document.write before the <BODY>, the results can be unexpected. Most often, you will find that *effectively* you have moved the <BODY> tag to the point of the write.

    (3) Why not just use alert( ) to find out the value for debugging purposes?

    (4) You can't change the entire style of an element as you are trying to do. You can only change one characteristic of the style at a time.

    (5) Your initial style for the body's cursor is illegal, since you specified a url but then omitted any actual url.

    So:
    Code:
    <script type="text/javascript" src="cookie.js"></script>
    <script type="text/javascript">
    
    function pgcursor() {
    	cursor=getCookie('cursor');
    	if (cursor!=null && cursor!="")
           {
               alert("Value of cursor is ::" + cursor + "::");
               // document.body.style.cursor="url("+cursor+ ")";
           }
    }
    </script>
    
    <body>
    ...

  • Users who have thanked Old Pedant for this post:

    rhyz (03-17-2009)

  • #3
    New Coder
    Join Date
    Mar 2009
    Posts
    23
    Thanks
    13
    Thanked 0 Times in 0 Posts
    Thanks but when i run your script i get no errors but the mouse still does not display and nor does the alert ???

    O my i so stupid sorry script works fine im such a idiot so so sorry thankyou so much
    Last edited by rhyz; 03-17-2009 at 12:07 PM.


  •  

    Posting Permissions

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