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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jul 2003
    Posts
    600
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Date Countdown Script

    Hey Guys,

    I have the following countdown JS code, which works well. However I want to add a series of dates to it, where it will automatically grab the next date and count it down, once the current value being counted down has passed. Has anyone done anything like this before?

    Here's the code I currently have:

    <script language="javascript">

    // Date/Countdown

    function showDate () {
    var now = new Date();
    var date = now.getDate();
    var month = now.getMonth() + 1;
    var year = now.getYear();

    currentDate = now.getMonth() + 1;

    var roundCDiv = document.getElementById('roundC');
    var showDate = month + "/" + date + "/" + year;
    //roundCDiv.innerHTML = showDate;

    // countdown
    var nextDateB = new Date("April 29, 2006");
    var diffB = nextDateB.getTime() - now.getTime();
    var daysLeftB = Math.ceil(diffB / (1000 * 60 * 60 * 24));
    var roundBDiv = document.getElementById('roundB');
    roundBDiv.innerHTML = daysLeftB;
    }
    </script>

    </head>

    <body onload="showDate();">

    <div id="roundB"></div>
    <!-- countdown value displays within div tag -->

    </body>

    Any suggestions would be greatly appreciated.

    Thanks Much.

  • #2
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    It looks like your code only countsdown once, or rather, simply does a date comparison and tells you how far apart they are.

    If you want to keep displaying a new "time till April, 29th 2006" every second, you can

    setInterval(showDate, 1000);

  • #3
    Regular Coder
    Join Date
    Jul 2003
    Posts
    600
    Thanks
    17
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Beagle
    It looks like your code only countsdown once, or rather, simply does a date comparison and tells you how far apart they are.

    If you want to keep displaying a new "time till April, 29th 2006" every second, you can

    setInterval(showDate, 1000);
    I more or less wanted a set of dates from a calendar (say 10), and wanted to countdown to the most recent one. Once that date has passed, then countdown to the next one, and then the next one, etc.


  •  

    Posting Permissions

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