[advanced search]
NamePros Domain Auction
Live Event This Thursday at 6PM EDT - Prebidding open now
12 members in the live chat room. Join Chat!
Register Rules & FAQ NP$ Store Active Threads Mark Forums Read
Go Back   NamePros.Com > Design and Development > Programming > CODE
User Name
Password

Old 09-13-2005, 09:23 PM   · #1
BLazeD
thedomainmatrix.com
 
BLazeD's Avatar
 
Name: Matt
Location: New Zealand
Trader Rating: (40)
Join Date: Apr 2004
Posts: 1,470
NP$: 316.00 (Donate)
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 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!


Please register or log-in into NamePros to hide ads
BLazeD is offline   Reply With Quote
Old 09-17-2005, 06:41 PM   · #2
stscac
A Wealth of Knowledge
 
stscac's Avatar
 
Trader Rating: (45)
Join Date: Aug 2004
Posts: 3,785
NP$: 1200.20 (Donate)
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.

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!

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   Reply With Quote
Old 09-18-2005, 04:28 AM   · #3
BLazeD
thedomainmatrix.com
 
BLazeD's Avatar
 
Name: Matt
Location: New Zealand
Trader Rating: (40)
Join Date: Apr 2004
Posts: 1,470
NP$: 316.00 (Donate)
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 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   Reply With Quote
Old 09-27-2005, 09:43 AM   · #4
stscac
A Wealth of Knowledge
 
stscac's Avatar
 
Trader Rating: (45)
Join Date: Aug 2004
Posts: 3,785
NP$: 1200.20 (Donate)
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   Reply With Quote
Old 09-27-2005, 12:07 PM   · #5
BLazeD
thedomainmatrix.com
 
BLazeD's Avatar
 
Name: Matt
Location: New Zealand
Trader Rating: (40)
Join Date: Apr 2004
Posts: 1,470
NP$: 316.00 (Donate)
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 all
Yup, it never worked

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

NamePros is a revenue sharing forum.

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

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 01:00 PM
simple code help unknowngiver Programming 5 08-17-2005 03:36 PM
vB skin, code, uShop, Google AdWords wanted for Scouts.com WebForging Web Development Wanted 3 03-30-2005 09:19 AM
simple redirect html/php wanted... DNQuest.com Website Development 5 07-24-2003 11:05 PM

Site Sponsors
http://www.mobisitetrader.com/ EscrowDNS Exdon
Advertise your business at NamePros
All times are GMT -7. The time now is 02:17 AM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0