Jump to content

Need a bit of help with the countdown timer.


imgrooot

Recommended Posts

Here's the code for the countdown timer. It works. At the end of the countdown, it's suppose to show the message "EXPIRED". But that message only shows once I reload the page. The countdown itself stops at 00:00:01. Is there a way to automatically show the message after that, instead of reloading the page to show it?

<style>
  div#counter{
      margin: 100px auto;
      width: 305px;
      padding:20px;
      border:1px solid #000000;
  }
  div#counter span{
      background-color: #00CAF6;
      padding:5px;
      margin:1px;
      font-size:30px;
  }
</style>

<?php 
  $target_date = '2019-01-12 05:40:00';
  $timeLeft = (strtotime($target_date) - time()) * 1000;
?>
<script src="javascripts/timer.js"></script>
<script>
$(document).ready(function(){

      var timeLeft = <?php echo $timeLeft ; ?>;
      var timer =  new Timer($('#counter'), timeLeft);
      
      if (timeLeft <= 0) {
        $('#counter').text('EXPIRED');
      }

});
</script>
<div id="counter">
  <span class="hour">00</span>
  <span class="min">00</span>
  <span class="sec">00</span>
</div>

 

Edited by imgrooot
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.