• Resolved convictedvapour

    (@chronicbubble)


    I have made a countdown time for 48 hours, and as soon as it counts down, it resets. I now need it to run a code on completion and allow it to reset as per the code below.

    How can I go about doing that?

    Thanks guys, your help is highly appreciated.

    The Countdown Code:

    <script type = "text/javascript">
    
    var timeInSecs;
    var ticker;
    
    function startTimer(secs) {
    timeInSecs = parseInt(secs);
    ticker = setInterval("tick()", 1000); 
    }
    
    function tick( ) {
    var secs = timeInSecs;
    if (secs > 0) {
    timeInSecs--; 
    }
    else {
    clearInterval(ticker);
    startTimer(172800);  // start again
    }
    
    var hours= Math.floor(secs/3600);
    secs %= 3600;
    var mins = Math.floor(secs/60);
    secs %= 60;
    var pretty = ( (hours < 10 ) ? "0" : "" ) + hours + ":" + ( (mins < 10) ? "0" : "" ) + mins + ":" + ( (secs < 10) ? "0" : "" ) + secs;
    document.getElementById("countdown").innerHTML = pretty;
    }
    
    startTimer(172800);  // 48 hours in seconds

    The code I need to run after the 48 hours has passed then reset as per above:

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter convictedvapour

    (@chronicbubble)

    I will rephrase better. I want to add an echo_do_shortcode in the code below as where it is commented to be added. Thanks!

    <script type = "text/javascript">
    
    var timeInSecs;
    var ticker;
    
    function startTimer(secs) {
    timeInSecs = parseInt(secs);
    ticker = setInterval("tick()", 1000); 
    }
    
    function tick( ) {
    var secs = timeInSecs;
    if (secs > 0) {
    timeInSecs--; 
    }
    else {
    clearInterval(ticker);
    //I WANT TO ADD A ECHO_DO_SHORTCODE HERE
    startTimer(172800);  // start again
    }
    
    var hours= Math.floor(secs/3600);
    secs %= 3600;
    var mins = Math.floor(secs/60);
    secs %= 60;
    var pretty = ( (hours < 10 ) ? "0" : "" ) + hours + ":" + ( (mins < 10) ? "0" : "" ) + mins + ":" + ( (secs < 10) ? "0" : "" ) + secs;
    document.getElementById("countdown").innerHTML = pretty;
    }
    
    startTimer(172800);  // 48 hours in seconds
    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Is the terminology “echo” bit not important? I’m saying this because echo is a PHP command and the solution will be wholly different in PHP than in JavaScript.

    Thread Starter convictedvapour

    (@chronicbubble)

    OK good point. It’s simply I am trying to make a countdown with HH:MM:SS that countdowns every 24 hours then resets itself and starts again. Then I can look to intergrate my custom coding.

    Thread Starter convictedvapour

    (@chronicbubble)

    Will code up something else! Thanks for the advice.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Run after HTML code?’ is closed to new replies.