Auto restart this countdown?

Discussion in 'JavaScript' started by MarcL, Aug 19, 2009.

  1. #1
    Here is the script. It is set to countdown to 4:20 but once 4:20 came around it just went blank and wont restart. Any hep?

    // ****  Time Zone Count Down Javascript  **** //
    /*
    Visit http://rainbow.arch.scriptmania.com/scripts/
     for this script and many more
    */
    
    ////////// CONFIGURE THE COUNTDOWN SCRIPT HERE //////////////////
    
    var month = '0';     //  '*' for next month, '0' for this month or 1 through 12 for the month 
    var day = '+0';       //  Offset for day of month day or + day  
    var hour = 16;        //  0 through 23 for the hours of the day
    var min = 20; 
    var tz = -5;         //  Offset for your timezone in hours from UTC
    var lab = 'tzcd';    //  The id of the page entry where the timezone countdown is to show
    
    function start() {displayTZCountDown(setTZCountDown(month,day,hour,tz),lab);}
    
        // **    The start function can be changed if required   **
    window.onload = start;
    
    ////////// DO NOT EDIT PAST THIS LINE //////////////////
    
    function setTZCountDown(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(20-(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 displayTZCountDown(countdown,tzcd) 
    {
    if (countdown < 0) document.getElementById(tzcd).innerHTML = "Sorry, you are too late."; 
    else {var secs = countdown % 60; 
    if (secs < 10) secs = '0'+secs;
    var countdown1 = (countdown - secs) / 60;
    var mins = countdown1 % 60; 
    if (mins < 10) mins = '0'+mins;
    countdown1 = (countdown1 - mins) / 60;
    var hours = countdown1 % 24;
    var days = (countdown1 - hours) / 24;
    document.getElementById(tzcd).innerHTML = +hours+ 'h : ' +mins+ 'm : '+secs+'s';
    setTimeout('displayTZCountDown('+(countdown-1)+',\''+tzcd+'\');',999);
    }
    }
    Code (markup):

     
    MarcL, Aug 19, 2009 IP
  2. MarcL

    MarcL Notable Member

    Messages:
    4,265
    Likes Received:
    82
    Best Answers:
    0
    Trophy Points:
    215
    #2
    Anyone have a idea?
     
    MarcL, Aug 20, 2009 IP
  3. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #3
    yeah, but unfortunately, it says:
    and the bit you want changed is there...

    :D :D :D






















    try this:
    find:
    if (countdown < 0) document.getElementById(tzcd).innerHTML = "Sorry, you are too late.";
    else {

    replace with:

    if (countdown < 0) {
    hour = 16; // reset values
    min = 20;
    var countdown = setTZCountDown(month,day,hour,tz);
    }
    // remove else and matching { }
    // {
    ...

    // }
     
    dimitar christoff, Aug 21, 2009 IP