Results 1 to 4 of 4

Thread: Javascript - setting cookies

  1. #1
    Join Date
    Jul 2003
    Posts
    1,524

    Javascript - setting cookies

    I believe I have the right idea, but I am having a hard time making it come together. The problem is to write the current time and date to a cookie during body onUnload. When the user comes back, we are supposed to check for a cookie. If a cookie exist, we are to write the date and time of last visit. If not, we are supposed to welcome the user to the site. When I run this in my Javascript debugger, it comes back with no errors. I'm sure there is something wrong, as it doesn't work. lol

    PHP Code:
    <html>
    <
    head>
    <
    title>cookies</title>
    <
    script type="text/javascript">
    function 
    getCurrentTime() {
    var 
    today = new Date()
    var 
    hour ""
    var exr ""
    if (today.getHours()==0) {
     
    hour 12
     ext 
    "a.m."
    } else if (today.getHours() < 12) {
     
    hour today.getHours()
     
    ext "a.m."
    } else if (today.getHours() == 12) {
     
    hour 12
     ext 
    "p.m."
    } else {
     
    hour today.getHours() - 12
     ext 
    "p.m."
    }
    document.cookies"cookieName=testcookie; hour=hour.toString(); minute=today.getMinutes().toString(); mille=today.getMilliseconds().toString();pmam=ext)"
    }
    function 
    getCurrentDate() {
    var 
    theday =new Date()
    document.cookies"cookieName=testcookie; monthofvisit=theday.getMonth() + 1; dateofvisit=theday.getDate(); yearofvisit=theday.getFullYear())"
    }
    </
    script>
    </
    head>
    <
    body onUnload "getCurrentTime(), getCurrentDate()">
    <
    script type="text/javascript">
    if(
    document.cookies=true) {
    document.write("You last visited us on: "document.cookies(monthofvisitdateofvisityearofvisithourminutemille))
    } else {
    document.write("Welcome this is your first visit to our site")
    }
    </
    script>
    </
    body>
    </
    html

  2. #2
    Join Date
    Jul 2003
    Posts
    1,524
    Anyone have any ideas??

  3. #3
    AMDave's Avatar
    AMDave is offline Seeker of the exit clause Moderator
    Site Admin
    Join Date
    Jun 2004
    Location
    Deep in a while loop
    Posts
    9,658
    Yes. I was reading up on this last night (because it's been a while since I played with cookies - yes I know, you shouldn't play with food :D ). I just PM'd you.
    . . . . . ___
    . . . . . . .\___/\______
    . . . . . . . \__AMD___\\__
    ---------------------------------------------

  4. #4
    Join Date
    Mar 2006
    Location
    South Carolina, USA
    Posts
    917
    I read on Fox news that Madonna's husband started doing cookies and he's not interested in sex any more. (of course, it could simply be with her) Personally, I try to stay away from them.

Posting Permissions

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