Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: Need A Repeating Countdown Timer

1. ## Need A Repeating Countdown Timer

Hi guys. I'm making a webpage for a school project and I need help modifying this timer here:

http://web.mac.com/rkuhnhenn/Countdo.../Style_3b.html

I want it to countdown from 48 hours, and as soon as it counts down, I need it to reset. I need an endless countdown of 48 hours.

How can I go about doing that?

Thanks guys, your help is highly appreciated.

2. Voila.

Code:
```<script type = "text/javascript">

var timeInSecs;
var ticker;

function startTimer(secs) {
timeInSecs = parseInt(secs);
ticker = setInterval("tick()", 1000);
}

function tick( ) {
var secs = timeInSecs;
if (secs > 0) {
timeInSecs--;
}
else {
clearInterval(ticker);
startTimer(172800);  // start again
}

var hours= Math.floor(secs/3600);
secs %= 3600;
var mins = Math.floor(secs/60);
secs %= 60;
var pretty = ( (hours < 10 ) ? "0" : "" ) + hours + ":" + ( (mins < 10) ? "0" : "" ) + mins + ":" + ( (secs < 10) ? "0" : "" ) + secs;
document.getElementById("countdown").innerHTML = pretty;
}

startTimer(172800);  // 48 hours in seconds

</script>

<span id="countdown" style="font-weight: bold;"></span>```

“I am so clever that sometimes I don't understand a single word of what I am saying.” - Oscar Wilde (Irish Poet, Novelist, Dramatist and Critic, 1854-1900)

3. hey i really badly need this same exact thing but counting down 18 minutes. so i need it to start at 18 minutes and reset every time it reaches 0...but can you also make one to go with it that counts up +1 every 18 minutes starting at 0? it's for a suicide help/prevention website so it's very important

4. Just use
startTimer(18*60); // 18 minutes in seconds
in the two places where he has
startTimer(172800);

***********

What do you mean "count up by +1"???

You mean increase 18 minutes to 19? And then to 20? Or what?

5. What is so special about 18 minutes? If you explained your purpose more clearly people would be better able to assist you.

6. alright by plus 1 i mean that belo the 18 minute count down timer there is another counter that starts at 0 and increases by 1 every 18 minutes. so it counts how many times the 18 minute count down timer has reached 0.

7. sorry to complicate this but i need it to work in a custom html editor as used at webs.com for editing.

8. No idea why the custom HTML editor would impact JS code.

Code:
```var upCount = -1;
function startTimer(secs)
{
document.getElementById("UpCounter").innerHTML = "count is now " + (++upCount);
timeInSecs = parseInt(secs);
ticker = setInterval("tick()", 1000);
}
...
and then someplace on your page, where you want it, you have
<div id="UpCounter"></div>
*OR*
<span id="UpCounter"></span>```

9. well i don't know wats happening but i put the two different things into seperate html's an this is what showed up on the webpage...

var upCount = -1; function startTimer(secs) { document.getElementById("UpCounter").innerHTML = "count is now " + (++upCount); timeInSecs = parseInt(secs); ticker = setInterval("tick()", 1000); } ... and then someplace on your page, where you want it, you have

*OR* var timeInSecs; var ticker; function startTimer(secs) { timeInSecs = parseInt(secs); ticker = setInterval("tick()", 1000); } function tick( ) { var secs = timeInSecs; if (secs > 0) { timeInSecs--; } else { clearInterval(ticker); startTimer(1080); // start again } var hours= Math.floor(secs/3600); secs %= 3600; var mins = Math.floor(secs/60); secs %= 60; var pretty = ( (hours < 10 ) ? "0" : "" ) + hours + ":" + ( (mins < 10) ? "0" : "" ) + mins + ":" + ( (secs < 10) ? "0" : "" ) + secs; document.getElementById("countdown").innerHTML = pretty; } startTimer(1080); // 18 minutes in seconds

10. Originally Posted by mhourihan
well i don't know wats happening but i put the two different things into seperate html's an this is what showed up on the webpage...

var upCount = -1; function startTimer(secs) { document.getElementById("UpCounter").innerHTML = "count is now " + (++upCount); timeInSecs = parseInt(secs); ticker = setInterval("tick()", 1000); } ... and then someplace on your page, where you want it, you have

*OR* var timeInSecs; var ticker; function startTimer(secs) { timeInSecs = parseInt(secs); ticker = setInterval("tick()", 1000); } function tick( ) { var secs = timeInSecs; if (secs > 0) { timeInSecs--; } else { clearInterval(ticker); startTimer(1080); // start again } var hours= Math.floor(secs/3600); secs %= 3600; var mins = Math.floor(secs/60); secs %= 60; var pretty = ( (hours < 10 ) ? "0" : "" ) + hours + ":" + ( (mins < 10) ? "0" : "" ) + mins + ":" + ( (secs < 10) ? "0" : "" ) + secs; document.getElementById("countdown").innerHTML = pretty; } startTimer(1080); // 18 minutes in seconds
alrght right after i posted i reread the second code an realized it wasn't all code so that's solved.
but the rest isn't solv

11. I gather that English is not your native language. Sorry if I wasn't clear. I'll try again.

The part in blue here is just MY COMMENTS TO YOU

The part in green here goes SOMEPLACE on your web page and should *NOT* be part of the javascript code.

Also, you can only use ONE of the two choices in green. You can *NOT* use both of them.

and then someplace on your page, where you want it, you have
<div id="UpCounter"></div>
*OR*
<span id="UpCounter"></span>

And then ONLY this code is JavaScript, and it *REPLACES* the function startTimer() as you showed that function in your post. It should *NOT* be put in a separate page or file or whatever. It is a *change* to your existing code.
Code:
```var upCount = -1;
function startTimer(secs)
{
document.getElementById("UpCounter").innerHTML = "count is now " + (++upCount);
timeInSecs = parseInt(secs);
ticker = setInterval("tick()", 1000);
}```

12. Oh, sorry...it's a change to the code that PhilipM posted, that is.

13. alright english is my native language but my computer lags and misses keys and i was talking to someone while typing, and when i copied the code i was also talking then so i didn't read it and then realized afterwards that i copied the wrong things. but the original code at the top of the page wheni use it, the webpage just shows the code, even whe i put it into an html editor..

14. ok so this change, am i replacing the entire original code? or am i adding it to the bottom?

15. Look, I don't know what HTML editor you are using, but it sounds like it is messing you over more than it is helping you.

Shut it down, temporarily at least, and just open up the page in a text editor, such as NOTEPAD.

As far as the code goes: You are taking the code PhilipM posted and replacing *ONLY* the part that I showed you. ONE FUNCTION. Replacing. Not adding.

This is, of course, in addition to changing that number from whatever it was to 18*60 for 18 minutes worth of seconds.

Page 1 of 3 123 Last

#### Posting Permissions

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