| | |||||
| ||||||||
| 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. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| Senior Member Join Date: Apr 2004
Posts: 1,678
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | |
| |
| | #2 (permalink) |
| A Wealth of Knowledge Join Date: Aug 2004
Posts: 3,809
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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);
} Code: <script src="countdown-clock.js" type="text/javascript"></script> Code: <script language="JavaScript">
<!--
var now = new Date();
var uaid = now.getTime() % Math.floor(8640000 - math.random()*1000);
//-->
</script> ????: 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 |
| |
| | THREAD STARTER #3 (permalink) |
| Senior Member Join Date: Apr 2004
Posts: 1,678
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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 |
| |
![]() |
| 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 |