I am missing something here. . . I am trying to make a 10 minute countdown timer. I found some code and modified it so it counts down from 10 minutes like I wanted, but now I have two problems.
1. I want it to stop at 0, and
2. I want a popup box when it gets there.
I have tried all sorts of combinations, and I cannot seem to figure out how to do this. can anyone point me in the right direction?
<SCRIPT TYPE="text/javascript" LANGUAGE="Javascript">
/* chrono.js
* Role : Simulate a stopwatch with display controls
* Projet : JsLib
* Author : Etienne CHEVILLARD (echevillard@users.sourceforge.net)
* Version : 1.3
* Creation : 25/04/2001
* Mise a jour : 23/02/2005
*/
// --- Global Variables ---
// variables defineing the lenth of time
var chrono_demarre=false; //does the timer start on page load
var chrono_ecoule=600000; //the starting time for the timer
var chrono_depart=0; //these two variables control the flow of the timer - this is the starting time
var chrono_dernier=0; // and this is the ending time. These are subtracted to count down or up.
// set the variables for dynamic display
var chrono_champ;
var chrono_timeout;
// ---Functions---
// is the stopwatch running? aka has the stop button been pushed
function actifChrono() {
return (chrono_demarre);
} // finish actifChrono()
// stop the stopwatch
function arreterChrono() {
if (chrono_demarre) {
chrono_dernier=(new Date()).getTime();
chrono_ecoule-=(chrono_dernier-chrono_depart);
chrono_demarre=false;
}
return true;
} // finish arreterChrono()
// activate dynamic display of the time mesurment
function chargerChronoDyna(champ) {
if (champ)
chrono_champ=eval(champ);
chrono_champ.value=tempsChrono();
chrono_timeout=window.setTimeout("chargerChronoDyna()", 10);
return true;
} // fin chargerChronoDyna(champ)
// display of time measurment previously activated
function dechargerChronoDyna() {
window.clearTimeout(chrono_timeout);
return true;
} // fin dechargerChronoDyna()
// start the stopwatch
function demarrerChrono() {
if (!chrono_demarre) {
chrono_depart=(new Date()).getTime();
chrono_demarre=true;
}
return true;
} // fin demarrerChrono()
// reset the stopwatch to default time
function RAZChrono() {
if (!chrono_demarre) {
chrono_ecoule=600000;
chrono_depart=0;
chrono_dernier=0;
}
return true;
} // finish RAZChrono()
// format the display time (if needed HH:)MM:SS:CC
function tempsChrono() {
var cnow;
if (chrono_demarre) {
chrono_dernier=(new Date()).getTime();
cnow=new Date(chrono_ecoule-(chrono_dernier-chrono_depart));
} else {
cnow=new Date(chrono_ecoule);
}
var ch=parseInt(cnow.getHours()) - 1; //if needed
var cm=cnow.getMinutes();
var cs=cnow.getSeconds();
var cc=parseInt(cnow.getMilliseconds()/10);
if (cc<10) cc="0"+cc;
if (cs<10) cs="0"+cs;
if (cm<10) cm="0"+cm;
return (cm+":"+cs+":"+cc);
} // finish tempsChrono()
<BODY onLoad="chargerChronoDyna('document.f.t')"
onUnload="dechargerChronoDyna()">
<FORM ACTION="GET" NAME="f">
<INPUT NAME="t" TYPE=TEXT VALUE="0:00:00:00" SIZE=12>
<INPUT TYPE=BUTTON VALUE="start/stop"
onClick="if (actifChrono()) arreterChrono(); else demarrerChrono();">
<INPUT TYPE=BUTTON VALUE="Reseto" onClick="RAZChrono();">
</FORM>
</SCRIPT>


Sign In
Create Account

Back to top









