Click to See Complete Forum and Search --> : Need help with a function problem


Hase
03-07-2003, 07:58 AM
Hello,

i used the code for the following counter:

http://javascript.internet.com/clocks/digital-countdown.html

Now i found out that the code has an error when the time he has to counter went by, so if you type in the date of 1.st January 2003 my Homesite is giving me a stupid error message. How can i fix that problem?
The Error says that i have to set a ; in line XX sign 1, but after setting the ; in the code, it tells me that it needs a ; in line XX too but on sign 2. That's curious, isn't it?

Please, may anybody help me?

I thought about to stop the function when the later date reaches the now date, but don't know how to stop it :(

Thx for any help.

khalidali63
03-07-2003, 08:23 AM
In other words you are trying to see how many days have been since the date you enter until today,well for that reason you will have to re-write allots of new code,here is why the existing code works on this condition

later=100
now=20
later-now = 80

but if you did something like this

later=20
now=100
later-now = -80

The code you have does not process minus number( its only to make you understand why its does not work)

So either you wil have to write your own code or some one might ehelp you here

Khalid

Hase
03-07-2003, 08:36 AM
The Mainproblem is that i just want the counter to stop when it reaches the date he had to counter to.

So when he has to count down til 23.Mar 12pm, any number of the counter should stop at 0 right when the time reaches 23.Mar 12pm and 1 second, but right then the error appears and i don't know how to fix it :(

Hase
03-07-2003, 09:38 AM
please any help ... i need the website with that **** code in a few hours :(

khalidali63
03-07-2003, 10:01 AM
Ohhkkay..

here you go, delete all of your code which is in the script tags and replace all the code including script tags with the following code


<script type="text/javascript">

var later = new Date("Jan 1 2004 00:00:00");
lm = later.getTime();
function getTime() {
c1 = new Image(); c1.src = "images/1c.gif";
c2 = new Image(); c2.src = "images/2c.gif";
c3 = new Image(); c3.src = "images/3c.gif";
c4 = new Image(); c4.src = "images/4c.gif";
c5 = new Image(); c5.src = "images/5c.gif";
c6 = new Image(); c6.src = "images/6c.gif";
c7 = new Image(); c7.src = "images/7c.gif";
c8 = new Image(); c8.src = "images/8c.gif";
c9 = new Image(); c9.src = "images/9c.gif";
c0 = new Image(); c0.src = "images/0c.gif";
Cc = new Image(); Cc.src = "images/Cc.gif";
now = new Date();
nm = now.getTime();
var stop = false;
if(nm<=lm){
//ENTER BELOW THE DATE YOU WISH TO COUNTDOWN TO

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);

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");
}
}else{
stop = true;
}
if(!stop){
newtime = window.setTimeout("getTime();", 1000);
}
}
// End -->
</script>




Cheers

Khalid

Hase
03-07-2003, 10:18 AM
YES! Thanks Man, what shall i say now .... well i do it like Michael Jackson: I LOVE YA! ;)

I am happy, man you saved my life!!!!

YOU ARE THE BEST! Thank you soooo much.

Hase

P.S.: That guy is wonderful ... wow ... yes yes yes!