Cookie example - where's the bug?

A

Asad

(Sorry if reposts, not sure if last one went ...)

I am trying to get a cookie going on my site. Here is the code first:

function setCookie()
{
if(document.cookie == "")
{
var someDate = new Date("December 31, 2023");
var expiryDate = someDate.toGMTString();
document.cookie = "0";

cookie_counter = document.cookie;
document.write ("Cookie Created: " + cookie_counter);
}
else
{
var temp = parseInt(cookie_counter)
temp = temp + 1
cookie_counter = temp
document.write ("Added 1 to Cookie: " + cookie_counter);
}
}

But this just doesn't work. The first time through, cookie is created
fine and I get a line that reads "Cookie Created: 0". But the second
and following time I keep getting "Added 1 to Cookie: NaN".

I can't figure out what's wrong. I don't even see any cookie file
created in my cookies folder under windows. I even set my IE security
levels to accept all cookies, but still nothing ...

Any ideas?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,470
Messages
2,571,809
Members
48,797
Latest member
PeterSimpson
Top