SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Threaded View

  1. #1
    SitePoint Zealot
    Join Date
    Jul 2001
    Location
    Houston
    Posts
    130
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need Help with JScript Counter Function

    I've got a counter function I found here that I'm trying to use. I've decided to try and alter the function so that it accepts two parameters: a start time and an end time to count to. My javascript skills are pretty bad, so I was hoping someone here might be able to help me get this thing working. I'm sure it's something really simple.

    I've put my changes to the function in red and the part that I think is causing the problem in blue.

    Code:
    function getTime(datCountFrom, datCountTo) {
    	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 datetime to countdown to
    	//later = new Date("Sep 5 2002 20:30:01");
    
    	// get numbers for time
    	days = (datCountTo - datCountFrom) / 1000 / 60 / 60 / 24;
    	daysRound = Math.floor(days);
    	hours = (datCountTo - datCountFrom) / 1000 / 60 / 60 - (24 * daysRound);
    	hoursRound = Math.floor(hours);
    	minutes = (datCountTo - datCountFrom) / 1000 /60 - (24 * 60 * daysRound) - (60 * hoursRound);
    	minutesRound = Math.floor(minutes);
    	seconds = (datCountTo - datCountFrom) / 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");
    	}
    
    	newtime = window.setTimeout("getTime(datCountFrom, datCountTo);", 1000);
    }
    I'm using the function like this:
    Code:
    datFrom = new Date();
    datTo = new Date("Sep 5 2002 20:30:01");
    
    ...
    
    <body onLoad="getTime(datFrom, datTo)">
    Last edited by writhe; Aug 26, 2002 at 10:15.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •