NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming > CODE
Reload this Page Wanted: Simple Countdown Timer Code

CODE This forum is for posting code snippets and example scripts that aren't quite tutorials, but could be useful for others. You may post code snippets and/or completed scripts that you've written and want to share here.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 09-13-2005, 10:23 PM THREAD STARTER               #1 (permalink)
Senior Member
 
BLazeD's Avatar
Join Date: Apr 2004
Posts: 1,678
BLazeD is a name known to allBLazeD is a name known to allBLazeD is a name known to allBLazeD is a name known to allBLazeD is a name known to allBLazeD is a name known to allBLazeD is a name known to allBLazeD is a name known to all
 



Lightbulb Wanted: Simple Countdown Timer Code


Hi there

I am just wondering if anyone is able to provide me with the code (PHP or HTML) for a text countdown timer.

The text will simply be:



? days, ? hours, ? minutes, and ? seconds until ....




I would prefer that the numbers (?) actually count down on the page (PHP?), or if they only give a value at the time the page is loaded (HTML?).

I have tried for the last hour to get one going, and I have, but it gives errors (java errrors).

Thanks for any help!
BLazeD is offline  
Old 09-17-2005, 07:41 PM   #2 (permalink)
A Wealth of Knowledge
 
stscac's Avatar
Join Date: Aug 2004
Posts: 3,809
stscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud of
 



Hey Matt

I got something for you. Although I cannot take credit for writing this, it does look pretty neat

Its definitely not php, because once php loads on a page, it has no more interactions with the server, thus cannot (as far as I know) continue to countdown without the help of a client side application.
????: NamePros.com http://www.namepros.com/code/123580-wanted-simple-countdown-timer-code.html

That is where the lovely javascript comes in. The following is copy and paste code from http://scripts.franciscocharrua.com/countdown-clock.php and should be saved as an external js file (countdown.js).

Code:
function countdown_clock(year, month, day, hour, minute, format)
         {
         //I chose a div as the container for the timer, but
         //it can be an input tag inside a form, or anything
         //who's displayed content can be changed through
         //client-side scripting.
         html_code = '<div id="countdown"></div>';
         
         document.write(html_code);
         
         countdown(year, month, day, hour, minute, format);                
         }
         
function countdown(year, month, day, hour, minute, format)
         {
         Today = new Date();
         Todays_Year = Today.getYear() - 2000;
         Todays_Month = Today.getMonth() + 1;                  
         
         //Convert both today's date and the target date into miliseconds.                           
         Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(), 
                                 Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime();                                 
         Target_Date = (new Date(year, month, day, hour, minute, 00)).getTime();                  
         
         //Find their difference, and convert that into seconds.                  
         Time_Left = Math.round((Target_Date - Todays_Date) / 1000);
         
         if(Time_Left < 0)
            Time_Left = 0;
         
         switch(format)
               {
               case 0:
                    //The simplest way to display the time left.
                    document.all.countdown.innerHTML = Time_Left + ' seconds';
                    break;
               case 1:
                    //More datailed.
                    days = Math.floor(Time_Left / (60 * 60 * 24));
                    Time_Left %= (60 * 60 * 24);
                    hours = Math.floor(Time_Left / (60 * 60));
                    Time_Left %= (60 * 60);
                    minutes = Math.floor(Time_Left / 60);
                    Time_Left %= 60;
                    seconds = Time_Left;
                    
                    dps = 's'; hps = 's'; mps = 's'; sps = 's';
                    //ps is short for plural suffix.
                    if(days == 1) dps ='';
                    if(hours == 1) hps ='';
                    if(minutes == 1) mps ='';
                    if(seconds == 1) sps ='';
                    
                    document.all.countdown.innerHTML = days + ' day' + dps + ' ';
                    document.all.countdown.innerHTML += hours + ' hour' + hps + ' ';
                    document.all.countdown.innerHTML += minutes + ' minute' + mps + ' and ';
                    document.all.countdown.innerHTML += seconds + ' second' + sps;
                    break;
               default: 
                    document.all.countdown.innerHTML = Time_Left + ' seconds';
               }
               
         //Recursive call, keeps the clock ticking.
         setTimeout('countdown(' + year + ',' + month + ',' + day + ',' + hour + ',' + minute + ',' + format + ');', 1000);
         }
Once the file has been saved, you are going to want to call the file by placing the following code in the header of the HTML page in which you want the countdown to appear.
Code:
<script src="countdown-clock.js" type="text/javascript"></script>
Now, find the spot in your HTML document where you want the countdown to appear. Place the following code in the exact spot within the HTML code where you want to countdown to appear.
Code:
    <script language="JavaScript">
    <!--
       var now = new Date();
       var uaid = now.getTime() % Math.floor(8640000 - math.random()*1000);
    //-->
    </script>
And Poof! You got it!
????: NamePros.com http://www.namepros.com/showthread.php?t=123580

A custom countdown. You can then style it with CSS, which is fairly standard.

Let me know if you need anything else

Good luck

-Steve
stscac is offline  
Old 09-18-2005, 05:28 AM THREAD STARTER               #3 (permalink)
Senior Member
 
BLazeD's Avatar
Join Date: Apr 2004
Posts: 1,678
BLazeD is a name known to allBLazeD is a name known to allBLazeD is a name known to allBLazeD is a name known to allBLazeD is a name known to allBLazeD is a name known to allBLazeD is a name known to allBLazeD is a name known to all
 



Cheers dude - will give it a shot. I already have some javascript for other stuff in my header, and everytime I try a method like above, that involves adding more javascript to my header - it never works.

I will try and figure it out, but dont expect much luck
BLazeD is offline  
Old 09-27-2005, 10:43 AM   #4 (permalink)
A Wealth of Knowledge
 
stscac's Avatar
Join Date: Aug 2004
Posts: 3,809
stscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud of
 



Haven't heard anything to see if it does indeed work.

Would be nice to let other users know if it did indeed work and what your environment was.

Thanks

-Steve
stscac is offline  
Old 09-27-2005, 01:07 PM THREAD STARTER               #5 (permalink)
Senior Member
 
BLazeD's Avatar
Join Date: Apr 2004
Posts: 1,678
BLazeD is a name known to allBLazeD is a name known to allBLazeD is a name known to allBLazeD is a name known to allBLazeD is a name known to allBLazeD is a name known to allBLazeD is a name known to allBLazeD is a name known to all
 



Yup, it never worked

I think it conficts with other stuff in my header
BLazeD is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
30 NP$ For Whoever Can Give Me Simple Code Snippet buddybuddha Programming 8 09-13-2005 02:00 PM
simple code help unknowngiver Programming 5 08-17-2005 04:36 PM
vB skin, code, uShop, Google AdWords wanted for Scouts.com WebForging Web Development Wanted 3 03-30-2005 10:19 AM
simple redirect html/php wanted... DNQuest.com Website Development 5 07-25-2003 12:05 AM

Liquid Web Smart Servers  
All times are GMT -7. The time now is 09:39 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger