Hello everyone. My name is Emil Nikolov(you can call me Emo). I`m from Bulgaria and this is my first post in this wonderful forum. I would to excuse me to my BAD english (i`m only 16 years old).
I`m developing some military web based game on PHP/MySQL and i need some countdown timer.
If you are play web based game you must know. There is a JavaScript timers in building menu. When you chose a building or research and click them, this timer start ticking and countdown. And when the countdown is finished the building has appear.
Timer should not be influenced by recharge or leaving the page or site. Might be saved in a database, no idea. Thank you in advance!
Countdown timer
Moderator: General Moderators
Re: Countdown timer
Hi Emo and welcome to the forum!
I did a simple countdown timer a week ago:
You can change these:
//Increment Second
s--;
total_secs--;
to
s++
total_secs++;
If you want it to increment (which is the original).
Also add a div element with id 'timer'
<div id="timer"></div>
I did a simple countdown timer a week ago:
Code: Select all
<script type="text/javascript">
//Timer Script
var s = 59;
var m = 0;
function timer() {
var total_secs;
//Add 0 before sek if below 10
if(s<10) sek = '0' + s;
else sek = s;
//Display Timer
document.getElementById('timer').innerHTML= 'Time: ' + m + ':' + sek;
//Increment Second
s--;
total_secs--;
//Second to Minute
if(s==60) {
//Reset second
s=0;
//Add minute
m++;
}
if(s==0) {
alert('Time\'s Up!');
}
}
//Initiate timer
setInterval("timer();", 1000);
</script>
//Increment Second
s--;
total_secs--;
to
s++
total_secs++;
If you want it to increment (which is the original).
Also add a div element with id 'timer'
<div id="timer"></div>
Re: Countdown timer
Thanks man, that is what i`m looking for. There was 1 mistake. I lil continue to work on this code and if a have some issues i lil write here.... and soon my first game will be done! Have a nice day man, and thank you again!

Re: Countdown timer
Hi, I met a problem already. When you refresh the page count starts again as I entered in the script. I can easily do it to remember where it is reached before a reload or refresh the page. But then the problem will be that while the page count is not counting closed time!
I forgot to say that almost nothing know JavaScript. Currently reading a book on AJAX.
I forgot to say that almost nothing know JavaScript. Currently reading a book on AJAX.
Re: Countdown timer
Hi, which function to use so I can see the time of the server, not on the user's computer?
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Countdown timer
Code: Select all
echo date('m-d-y');