...

View Full Version : Help with Multiple Countdowns script



therichboy
12-17-2007, 04:54 PM
I found this great script that counts down based on how many days in advance i tell, like a 'limited time offer' that resets

the problem is, i can only place one instance of this.

Can someone help modify the script so i can make the same countdown show up multiple times on the same page.

heres the code

I place this where i want the countdown to show up

<span id="cd"></span>

then...



var month = '0'; // 1 through 12 or '*' for next month, '0' for this month
var day = '+2'; // day of month or + day offset
var hour = 1; // 0 through 23 for the hour of the day
var tz = 0; // offset in hours from UTC to your timezone
var lab = 'cd'; // id of the entry on the page where the counter is to be inserted

function start() {displayCountdown(setCountdown(month,day,hour,tz),lab);}
window.onload = start;

// Countdown Javascript
// copyright 20th April 2005, by Stephen Chapman
// permission to use this Javascript on your web page is granted
// provided that all of the code in this script (including these
// comments) is used without any alteration
// you may change the start function if required
function setCountdown(month,day,hour,tz) {var toDate = new Date();if (month == '*')toDate.setMonth(toDate.getMonth() + 1);else if (month > 0) { if (month <= toDate.getMonth())toDate.setYear(toDate.getYear() + 1);toDate.setMonth(month-1);}if (day.substr(0,1) == '+') {var day1 = parseInt(day.substr(1));toDate.setDate(toDate.getDate()+day1);} else{toDate.setDate(day);}toDate.setHours(hour);toDate.setMinutes(0-(tz*60));toDate.setSeconds(0);var fromDate = new Date();fromDate.setMinutes(fromDate.getMinutes() + fromDate.getTimezoneOffset());var diffDate = new Date(0);diffDate.setMilliseconds(toDate - fromDate);return Math.floor(diffDate.valueOf()/1000);}
function displayCountdown(countdn,cd) {if (countdn < 0) document.getElementById(cd).innerHTML = "Sorry, you are too late."; else {var secs = countdn &#37; 60; if (secs < 10) secs = '0'+secs;var countdn1 = (countdn - secs) / 60;var mins = countdn1 % 60; if (mins < 10) mins = '0'+mins;countdn1 = (countdn1 - mins) / 60;var hours = countdn1 % 24;var days = (countdn1 - hours) / 24;document.getElementById(cd).innerHTML = days+' Day '+hours+' Hours '+mins+' Minutes and '+secs +' Seconds Left!';setTimeout('displayCountdown('+(countdn-1)+',\''+cd+'\');',999);}}

Thanks guys

The Rich Boy - Nate
www.TheRichBoy.com (example of script on my webpage, towards the bottom)

Trinithis
12-17-2007, 05:36 PM
Here. Just add more countdown info into the arrays I gave the code:
Example
var lab = [cd1, cd2, cd3, cd4, etc];
Do this for all the variables.



var month = ['0', '1']; // 1 through 12 or '*' for next month, '0' for this month
var day = ['+2', '+8']; // day of month or + day offset
var hour = [1, 4]; // 0 through 23 for the hour of the day
var tz = [0, 0]; // offset in hours from UTC to your timezone
var lab = ['cd', 'cd2']; // id of the entry on the page where the counter is to be inserted

function start() {
for(var i = month.length; i >= 0; --i)
displayCountdown(setCountdown(
month[i], day[i], hour[i], tz[i]
), lab[i]);
}
window.onload = start;

// Countdown Javascript
// copyright 20th April 2005, by Stephen Chapman
// permission to use this Javascript on your web page is granted
// provided that all of the code in this script (including these
// comments) is used without any alteration
// you may change the start function if required
function setCountdown(month, day, hour, tz) {
var toDate = new Date();
if(month == '*')
toDate.setMonth(toDate.getMonth() + 1);
else
if(month > 0) {
if(month <= toDate.getMonth())toDate.setYear(toDate.getYear() + 1);
toDate.setMonth(month - 1);
}
if(day.substr(0,1) == '+') {
var day1 = parseInt(day.substr(1));
toDate.setDate(toDate.getDate() + day1);
}
else
toDate.setDate(day);
toDate.setHours(hour);
toDate.setMinutes(0 - (tz * 60));
toDate.setSeconds(0);
var fromDate = new Date();
fromDate.setMinutes(fromDate.getMinutes() + fromDate.getTimezoneOffset());
var diffDate = new Date(0);
diffDate.setMilliseconds(toDate - fromDate);
return Math.floor(diffDate.valueOf() / 1000);
}

function displayCountdown(countdn, cd) {
if(countdn < 0)
document.getElementById(cd).innerHTML = "Sorry, you are too late.";
else {
var secs = countdn % 60;
if (secs < 10)
secs = '0' + secs;
var countdn1 = (countdn - secs) / 60;
var mins = countdn1 % 60;
if(mins < 10)
mins = '0' + mins;
countdn1 = (countdn1 - mins) / 60;
var hours = countdn1 % 24;
var days = (countdn1 - hours) / 24;
document.getElementById(cd).innerHTML = days + ' Day ' + hours + ' Hours ' + mins +
' Minutes and ' + secs + ' Seconds Left!';
setTimeout((function(countdn, cd) {
return function() {
displayCountdown(countdn - 1, cd);
};
})(countdn, cd), 1000);
}
}

Philip M
12-17-2007, 05:41 PM
You must rename all the functions and variable names to avoid any duplication.

e.g.

var month1 = '0';
var day1 = '+2';

function start1() {

<span id="cd1"></span>

and then use sufffix 2,3,4 etc. in further instances.

delete window.onload = start;
and replace by

<BODY onload = "start1(); start2(); start3() .... and so on

therichboy
12-17-2007, 06:13 PM
okay, well i just tried and tried, both ways and i can not get it to work.

will someone take 60 seconds and set this up properly so it will work and send me the code.

therichboy
12-17-2007, 11:36 PM
Bump for help. I have been trying forever, and cant get it to work.

Thanks
Whoever helps me, ill give my "Money For Real" ebook to for free, where I teach how I make over $30,000 per month online.

Trinithis
12-18-2007, 02:59 AM
Forgot to -1 from the array length. Here's a working page with multiple countdowns.


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Test</title>
</head>
<body><div>

<div id="cd1"></div>
<div id="cd2"></div>


<script type="text/javascript">

var month = ['0', '0']; // 1 through 12 or '*' for next month, '0' for this month
var day = ['+2', '+22']; // day of month or + day offset
var hour = [1, 4]; // 0 through 23 for the hour of the day
var tz = [0, 19]; // offset in hours from UTC to your timezone
var lab = ['cd1', 'cd2']; // id of the entry on the page where the counter is to be inserted

function start() {
for(var i = month.length - 1; i >= 0; --i)
displayCountdown(setCountdown(
month[i], day[i], hour[i], tz[i]
), lab[i]);
}
window.onload = start;

// Countdown Javascript
// copyright 20th April 2005, by Stephen Chapman
// permission to use this Javascript on your web page is granted
// provided that all of the code in this script (including these
// comments) is used without any alteration
// you may change the start function if required
function setCountdown(month, day, hour, tz) {
var toDate = new Date();
if(month == '*')
toDate.setMonth(toDate.getMonth() + 1);
else
if(month > 0) {
if(month <= toDate.getMonth())toDate.setYear(toDate.getYear() + 1);
toDate.setMonth(month - 1);
}
if(day.substr(0,1) == '+') {
var day1 = parseInt(day.substr(1));
toDate.setDate(toDate.getDate() + day1);
}
else
toDate.setDate(day);
toDate.setHours(hour);
toDate.setMinutes(0 - (tz * 60));
toDate.setSeconds(0);
var fromDate = new Date();
fromDate.setMinutes(fromDate.getMinutes() + fromDate.getTimezoneOffset());
var diffDate = new Date(0);
diffDate.setMilliseconds(toDate - fromDate);
return Math.floor(diffDate.valueOf() / 1000);
}

function displayCountdown(countdn, cd) {
if(countdn < 0)
document.getElementById(cd).innerHTML = "Sorry, you are too late.";
else {
var secs = countdn % 60;
if (secs < 10)
secs = '0' + secs;
var countdn1 = (countdn - secs) / 60;
var mins = countdn1 % 60;
if(mins < 10)
mins = '0' + mins;
countdn1 = (countdn1 - mins) / 60;
var hours = countdn1 % 24;
var days = (countdn1 - hours) / 24;
document.getElementById(cd).innerHTML = days + ' Day ' + hours + ' Hours ' + mins +
' Minutes and ' + secs + ' Seconds Left!';
setTimeout((function(countdn, cd) {
return function() {
displayCountdown(countdn - 1, cd);
};
})(countdn, cd), 1000);
}
}

</script>
</div>
</body>
</html>

therichboy
12-18-2007, 10:20 AM
Thanks times a million. You saved me hours of headaches.

Like i said, here's my MAKE MONEY ebook free. The one I normally sell on my webpage for $97 at http://www.TheRichBoy.com

Here is your download link.

http://www.unreal-deals.com/ebooks1111/!eBooks/e014realmoneyebook.zip

Nate - The Rich Boy



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum