PDA

View Full Version : counter


Dijkdrent
12-15-2002, 10:47 AM
I have to make a lotery for our Soccer club in Holland.
Everything is working but:
I need a counter script, that's working without the internet. Every the page refresh the people should see wich price is on now.
SO not a number generator but a simple off-line counter..
Thanx

ConfusedOfLife
12-15-2002, 11:52 AM
You have to use cookies.

Something like this might help:

<script>
function DesiredDate(when)
{
expireDate = new Date();
if ( when == "Future" )
expireDate.setMonth( expireDate.getMonth() + 120 );
else
expireDate.setMonth( expireDate.getMonth() - 1 );
return expireDate;
}

function setCookie(Name, Value, Expires)
{
document.cookie = escape(Name) + "=" + Value + "; " +
( (Expires) ? ("expires=" + Expires.toGMTString() ) : "");
}

currNum = 0;
// Getting the number
if ( document.cookie !="")
{
all = document.cookie.split("; ");
currNum = parseInt(all[0].split("=")[1]);
}

document.write(currNum);

// Incerementing the number by 1
setCookie( "Number", currNum+1, DesiredDate("Future"));
</script>

Dijkdrent
12-15-2002, 11:56 AM
Thanks a lot!!!!!!!!!!
That's the one Iám looking for the last 2 days, Now within 1 hour result...
Thanx

Dijkdrent
12-15-2002, 11:58 AM
Is there a way to make the number larger, so the people can see it, it's small now..

scroots
12-15-2002, 09:15 PM
for a guess:

document.write("<H1>");
document.write(currNum);
document.write("</H1>");

if it is wrong let me know and i will look it up.

scroots

whammy
12-16-2002, 04:47 AM
When you say "off-line counter" do you intend for this to show the same value to different users on a local area network? If so, cookies are not the answer since they are only saved to a client's hard drive.

Please clarify what you mean by "off-line counter".