The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Simple Countdown help

I'm looking for a little help with a countdown. I've tried a few things but just can't get them to work so i'm hoping someone out here can help me out. I'm looking for a javascript that will do a 3 minute countdown and display it on the screen, preferably not in a textbox, but i'm not picky.

Here is how it works. Someone will make a selection from a form. The date/time of that selection is then stored in a database. I want to use the date time stored in the database as my starting time and then countdown 3 minutes. After 3 minutes I would like a message saying Times Up, please make a selection.

I think you mentioned previously that your using php as your server side language. So make a simple query to your database and alter this value according to the value that the user has entered. The rest should be done using php and if the date matches use the peice of code below.

Keep time with refresh...

Andrew-J2000,

Thanks for your help, I forgot a key point of information when I was explaining what I needed. As the user refreshes it needs to keep the time of the count down, not start at 10 again. When on makes a selection, the date is updated in the database. What I have tried is a countdown using a date. The start date is what is in the database, then the future date (the date counting down to) is 3 minutes in the future from the date in the database. I just can't get it to work. Can you enhance your script to do the above? I can get the date out of the database and populate the variables. I just can't get the countdown to execute.

You should know that when a page is refreshed, all variables that were calculated by javascript functions called by that page are erased.
The most simple way to make javascript information persistent is to store it in a cookie. If it is a continuously changing variable, this might be problematic. Don't know, maybe you could use something like onunload or something.
(You'll have to ask yourself if it will be worth the trouble to make it work exactly like you envisioned or to make a compromise...)