Click to See Complete Forum and Search --> : timer countdown
tinernet
07-07-2003, 02:10 PM
im tryin to make a timer countdown that visbly display how long you have left. i can easily do it with setTimeout that jsut displays an alert but i cant get anythin workin that displays the time you have left and then displays the alert at 0.help!
Charles
07-07-2003, 02:21 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Time Until Nats</title>
<script type="text/javascript">
<!--
Date.ONE_SECOND = 1000;
Date.ONE_MINUTE = Date.ONE_SECOND * 60;
Date.ONE_HOUR = Date.ONE_MINUTE * 60;
Date.ONE_DAY = Date.ONE_HOUR * 24;
Date.ONE_WEEK = Date.ONE_DAY * 7;
function TimeUntil (d) {this.time = d.getTime ? d.getTime() : Date.parse(d)}
TimeUntil.prototype.valueOf = function () {return this.time - new Date ().getTime()}
TimeUntil.prototype.toString = function () {
var t = Math.abs(this.valueOf());
var d = Math.floor (t / Date.ONE_DAY);
var h = Math.floor ((t % Date.ONE_DAY) / Date.ONE_HOUR);
var m = Math.floor ((t % Date.ONE_HOUR) / Date.ONE_MINUTE);
var s = Math.floor ((t % Date.ONE_MINUTE) / Date.ONE_SECOND);
return (this.valueOf () < 0 ? '-' : '') + [d, d == 1 ? 'day' : 'days', [h, m < 10 ? '0' + m : m, s < 10 ? '0' + s : s].join(':')].join(' ');
}
var time = new TimeUntil ('2 August 2003 10:00 CDT');
document.write('<p><span id="time">',time , '</span> until Nats.</p>');
if (document.getElementById) var int = setInterval ("if (time < 0) {clearInterval(int); alert('The 2003 National Hooverball championship has begun!')} else {document.getElementById('time').replaceChild(document.createTextNode (time), document.getElementById('time').firstChild)}",0.2 * Date.ONE_SECOND);
// -->
</script>
tinernet
07-07-2003, 02:23 PM
that is exactly the same as the free ones iv been lookin for. i just want it to count down seconds not a date or anythin, it only needs to count down 90 seconds. surely theres a simpler way!?