Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Website Design/Showcase (http://www.chiefdelphi.com/forums/forumdisplay.php?f=64)
-   -   Help: Looking for javascript countdown script (http://www.chiefdelphi.com/forums/showthread.php?t=54978)

Compnerd 24-02-2007 22:09

Help: Looking for javascript countdown script
 
Hi everyone, I am looking for a countdown script using javascript. If you have one, please let me know!

Uberbots 24-02-2007 22:21

Re: Help: Looking for javascript countdown script
 
This is a simple function that i use on our website.
PHP Code:

function update(divIDseconds) {
        
obj document.getElementById(divID);
        var 
now = new Date();
        var 
output "";
        var 
dayshoursminutessecond;
        var 
timeUntil seconds Math.round(now.valueOf()/1000);
        
        
days Math.floor(timeUntil/86400);  timeUntil -= days*86400;
        
hours Math.floor(timeUntil/3600);  timeUntil -= hours*3600;
        
minutes Math.floor(timeUntil/60);  timeUntil -= minutes*60;
        
second Math.floor(timeUntil);
        
        
output += days " Days, " hours " Hours, " minutes " Minutes, " second " Seconds";
        
        
obj.innerHTML output;
        
window.setTimeout("update('" divID "', " seconds ")"1000);
    } 

You supply the ID of the tag you want to fill with the countdown, and the UNIX timestamp of the event that will be occurring. make sure that you set a preliminary timeout function before using it the first time. for example:
PHP Code:

window.setTimeout("update('feild0', 1173963600)"0); 

just for clarification, despite the tag, it is javascript.

fimmel 24-02-2007 22:25

Re: Help: Looking for javascript countdown script
 
also Dynamic Drive has tins of cool javascript samples. here is one that does a countdown. http://www.dynamicdrive.com/dynamici...lcountdown.htm

/forest

pheadxdll 24-02-2007 23:44

Re: Help: Looking for javascript countdown script
 
Any of the above scripts are acceptable. Here's ours:

Code:

 
dateFuture = new Date(2007,2,28,24,0,0); // Set the date

function GetCount(){
   
            dateNow = new Date();                                                                        //grab current date
            amount = dateFuture.getTime() - dateNow.getTime();                //calc milliseconds between dates
            delete dateNow;
   
            // time is already past
            if(amount < 0){
                    document.getElementById('countbox').innerHTML="Now!";
            }
            // date is still good
            else{
                    days=0;hours=0;mins=0;secs=0;out="";
   
                    amount = Math.floor(amount/1000);//kill the "milliseconds" so just secs
   
                    days=Math.floor(amount/86400);//days
                    amount=amount%86400;
   
                    hours=Math.floor(amount/3600);//hours
                    amount=amount%3600;
   
                    mins=Math.floor(amount/60);//minutes
                    amount=amount%60;
   
                    secs=Math.floor(amount);//seconds
   
                    if(days != 0){out += days +" day"+((days!=1)?"s":"")+", ";}
                    if(days != 0 || hours != 0){out += hours +" hour"+((hours!=1)?"s":"")+", ";}
                    if(days != 0 || hours != 0 || mins != 0){out += mins +" minute"+((mins!=1)?"s":"")+", ";}
                    out += secs +" seconds";
                    document.getElementById('countbox').innerHTML=out + " until we attend the Palmetto Regional in SC!";
   
                    setTimeout("GetCount()", 1000);
            }
    }

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

Make a div with an id countbox where you want the timer to be. Done!

Note: Its set currently to the Palmetto Regional, change the date to whatever you want :P


All times are GMT -5. The time now is 16:23.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi