Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

looping countdown clock 1

Status
Not open for further replies.

2DaysAway

Programmer
Dec 29, 2007
2
US
Does anyone have/or can anyone provide me with a javascript that will countdown from 10 minutes and start over by itself when it reaches zero? basically just a loop displaying min and secs. thats all.

I'd appreciate it.
 
Hey I just quickly wrote this up, it still needs some editing but hopefully it can get you started ..

/* Minutes to count down from */
var minutes = 10;
/* Total seconds of countdown */
var totalSeconds = 60 * minutes;

/* The div that will display the clock */
var clockDiv;

/* Intialize clock */
function initClock() {
clockDiv = document.getElementById('clock'); // grab the clock div;
setInterval('decreaseSecond()', 1000); // Start an interval every 1 second(1000 milliseconds)
}

/* Decrease the second, re-display clock */
function decreaseSecond() {
totalSeconds--; // decrease seconds
displayClock(); // show clock
}

/* Format total seconds to minutes and seconds */
function displayClock() {
var min = Math.floor(totalSeconds / 60); // Find minutes
var sec = (totalSeconds % 60); // Find seconds
clockDiv.innerHTML = min+':'+ (sec < 10 ? '0'+sec : sec); // Display Countdown
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top