Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Help with Multiple Countdowns script

    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)

  • #2
    Regular Coder
    Join Date
    Jun 2007
    Location
    USA
    Posts
    527
    Thanks
    26
    Thanked 74 Times in 72 Posts
    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.

    Code:
    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);
      }
    }
    Trinithis

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,303
    Thanks
    203
    Thanked 2,562 Times in 2,540 Posts
    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

  • #4
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #5
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #6
    Regular Coder
    Join Date
    Jun 2007
    Location
    USA
    Posts
    527
    Thanks
    26
    Thanked 74 Times in 72 Posts
    Forgot to -1 from the array length. Here's a working page with multiple countdowns.
    Code:
    <!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>
    Trinithis

  • #7
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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/ebooks11...moneyebook.zip

    Nate - The Rich Boy


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •