Topic: JavaScript Timer
Share/Save/Bookmark
Description: This code will show you how to implement a timer with Javascript
 

 

window.onload = function() { InitializeTimer(); }

var secs;
var timerID = null;
var timerRunning = false;
var delay = 1000 // one-thousands of a second

function InitializeTimer() {

// Set length of the timer, in seconds
secs = 10;
StopTheClock();
StartTheTimer();

}

function StopTheClock() {

if (timerRunning) {

clearTimeout(timerID);

}

timerRunning = false;

}

function StartTheTimer() {

if (secs == 0) {

StopTheClock();

// here's where you put something useful that's

// supposed to happen after the allotted time.

// For example, you could display a message:

//alert('test');

}

else {

//self.status = secs;

secs = secs - 1;

timerRunning = true;

timerID = self.setTimeout("StartTheTimer()", delay);

if (secs == 2 || secs ==3) {

setText();

}

var sliderDeposit = $find("<%: radDeposit.ClientID %>");

if (!sliderDeposit) return;

sliderDeposit.set_value(sliderDeposit.get_value());

var sliderNumberOfYears = $find("<%: radNumberOfYears.ClientID %>");

if (!sliderNumberOfYears) return;

sliderNumberOfYears.set_value(sliderNumberOfYears.get_value());

var sliderInterestRate = $find("<%: radInterestRate.ClientID %>");

if (!sliderInterestRate) return;

sliderInterestRate.set_value(sliderInterestRate.get_value());

// This code doesn't do what I want it to, yet

// ShowRadToolTip(tooltipDeposit, sliderDeposit);

// ShowRadToolTip(tooltipNumberOfYears, sliderNumberOfYears);

// ShowRadToolTip(tooltipInterestRate, sliderInterestRate);

tooltipDeposit.updateLocation();

tooltipNumberOfYears.updateLocation();

tooltipInterestRate.updateLocation();

}

}



Insert some steps here
  • Step 1
  • Step 2
  • Step 3
This is where you would add some code

More Code