Click to See Complete Forum and Search --> : Countdown Javascript Editing
Ax Slinger
08-20-2003, 06:18 AM
Hi,
Can anyone show me how to change the number of days from 999 to 99999 in this Digital Countdown (http://javascript.internet.com/clocks/digital-countdown.html) Javascript? When I try doing it, I get the extra digits to display, but the countdown is wrong. The math functions don't calculate properly.
I'd sure appreciate it. :)
Thanks,
Ax
requestcode
08-20-2003, 06:43 AM
You don't change the number of days, but the date that you want to count down to. This line:
later = new Date("Jan 1 2004 0:00:01");
Is what you want to change to get it to count down to a specific date and time.
Ax Slinger
08-20-2003, 09:36 AM
The way the code is written, there is a limit of 999 days. Putting in a date father off than 999 days causes an error. So it isn't just a matter of a date change. The code has to be rewritten to add two more digits. As I said, I can get the images to show, but the math is wrong for all dates above 999 days.
Here's an Example Image (http://pcpitstop.ibforums.com/axslinger/countdown/countdown.gif).
Fig. A is what it is now, Fig. B is what I need it to display. (Accurately...) :)
Ax Slinger
08-20-2003, 11:28 PM
I still need help with this. So...
Bump! :)
Exuro
08-21-2003, 12:45 AM
Wow, that was interesting... Anyway, try this:
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
var DaysLeft;
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
//Created by DendE PhisH
function getTime() {
c1 = new Image(); c1.src = "1c.gif";
c2 = new Image(); c2.src = "2c.gif";
c3 = new Image(); c3.src = "3c.gif";
c4 = new Image(); c4.src = "4c.gif";
c5 = new Image(); c5.src = "5c.gif";
c6 = new Image(); c6.src = "6c.gif";
c7 = new Image(); c7.src = "7c.gif";
c8 = new Image(); c8.src = "8c.gif";
c9 = new Image(); c9.src = "9c.gif";
c0 = new Image(); c0.src = "0c.gif";
Cc = new Image(); Cc.src = "Cc.gif";
now = new Date();
//ENTER BELOW THE DATE YOU WISH TO COUNTDOWN TO
later = new Date("Jan 1 2277 0:00:01");
days = (later - now) / 1000 / 60 / 60 / 24;
daysRound = Math.floor(days);
hours = (later - now) / 1000 / 60 / 60 - (24 * daysRound);
hoursRound = Math.floor(hours);
minutes = (later - now) / 1000 /60 - (24 * 60 * daysRound) - (60 * hoursRound);
minutesRound = Math.floor(minutes);
seconds = (later - now) / 1000 - (24 * 60 * 60 * daysRound) - (60 * 60 * hoursRound) - (60 * minutesRound);
secondsRound = Math.round(seconds);
DaysLeft=daysRound;
if (secondsRound <= 9) {
document.images.g.src = c0.src;
document.images.h.src = eval("c"+secondsRound+".src");
}
else {
document.images.g.src = eval("c"+Math.floor(secondsRound/10)+".src");
document.images.h.src = eval("c"+(secondsRound%10)+".src");
}
if (minutesRound <= 9) {
document.images.d.src = c0.src;
document.images.e.src = eval("c"+minutesRound+".src");
}
else {
document.images.d.src = eval("c"+Math.floor(minutesRound/10)+".src");
document.images.e.src = eval("c"+(minutesRound%10)+".src");
}
if (hoursRound <= 9) {
document.images.y.src = c0.src;
document.images.z.src = eval("c"+hoursRound+".src");
}
else {
document.images.y.src = eval("c"+Math.floor(hoursRound/10)+".src");
document.images.z.src = eval("c"+(hoursRound%10)+".src");
}
if (daysRound <= 9) {
document.images.x.src = c0.src;
document.images.a.src = c0.src;
document.images.b.src = eval("c"+daysRound+".src");
}
if (daysRound <= 99) {
document.images.x.src = c0.src;
document.images.a.src = eval("c"+Math.floor((daysRound/10)%10)+".src");
document.images.b.src = eval("c"+Math.floor(daysRound%10)+".src");
}
if (daysRound <= 999){
document.images.x.src = eval("c"+Math.floor(daysRound/100)+".src");
document.images.a.src = eval("c"+Math.floor((daysRound/10)%10)+".src");
document.images.b.src = eval("c"+Math.floor(daysRound%10)+".src");
}
if (daysRound <= 9999){
document.images.i.src = eval("c"+Math.floor(daysRound/1000)+".src");
document.images.x.src = eval("c"+Math.floor(daysRound/100)%10+".src");
document.images.a.src = eval("c"+Math.floor((daysRound/10)%10)+".src");
document.images.b.src = eval("c"+Math.floor(daysRound%10)+".src");
}
if (daysRound <= 99999){
document.images.j.src = eval("c"+Math.floor(daysRound/10000)+".src");
document.images.i.src = eval("c"+Math.floor((daysRound/1000)%10)+".src");
document.images.x.src = eval("c"+Math.floor((daysRound/100)%10)+".src");
document.images.a.src = eval("c"+Math.floor((daysRound/10)%10)+".src");
document.images.b.src = eval("c"+Math.floor(daysRound%10)+".src");
}
newtime = window.setTimeout("getTime();", 1000);
}
// End -->
</script>
</HEAD>
<BODY onLoad="getTime()">
<div align="center">
<h3>Countdown to New Years (2277)</h3>
</div>
<center>
<table><tr><td bgcolor="black" valign="bottom">
<img height=21 src="0c.gif" width=16 name=j>
<img height=21 src="0c.gif" width=16 name=i>
<img height=21 src="0c.gif" width=16 name=x>
<img height=21 src="0c.gif" width=16 name=a>
<img height=21 src="0c.gif" width=16 name=b>
<img height=21 src="Cc.gif" width=9 name=c>
<img height=21 src="0c.gif" width=16 name=y>
<img height=21 src="0c.gif" width=16 name=z>
<img height=21 src="Cc.gif" width=9 name=cz>
<img height=21 src="0c.gif" width=16 name=d>
<img height=21 src="0c.gif" width=16 name=e>
<img height=21 src="Cc.gif" width=9 name=f>
<img height=21 src="0c.gif" width=16 name=g>
<img height=21 src="0c.gif" width=16 name=h>
</td></tr></table>
</center>
<div align="center">
<h4>(Days : Hours : Minutes : Seconds)</h4>
</div>
</BODY>
</HTML>
Ax Slinger
08-21-2003, 03:02 AM
Exuro, you are DA MAN! You did it! :D
Now that I see it could be done, I looked at your code and I see how you did it, and why it didn't work for me. At least I was on the right track, even though I didn't understand how these math formulas work. But I think I get the idea now. That if (daysRound <= 999){ to if (daysRound <= 9999){ to if (daysRound <= 99999){ part was what was throwing me...
Thank you very, very much! :)