0

I just got a tutorial that integrate PHP date function and jQuery.

i want to customize the script so on specific time reach its redirect to another page.

i tried to do my self but its not working correctly. I have included the tutorial link here.

Tutorial LInk

PHP code to fetch date from server

<?php
date_default_timezone_set('GMT');
$currentTime = date('H:i:s');
$currentDay = date('w');
$delTimeStart = '00:00:00';
$delTimeEnd = '14:30:00';
if ($currentTime >= $delTimeStart && $currentTime < $delTimeEnd && $currentDay > 0 && $currentDay < 6){
    $css = 'display: block;';
} else {
    $css = 'display: none;';
}
?>

JS script

<script type="text/javascript">
$('#countdowntimer').countdown('<?php $date = strtotime("+1 day"); echo date('Y/m/d', $date); ?> 14:30:00').on('update.countdown', function(event) {
    var $this = $(this).html(event.strftime(''
        + '%H Hours '
        + '%M Minutes '
        + '%S Seconds'
    ));
});
</script>
2
  • what error you get...? is there any error in console.? mathewporter.co.uk/dev/del-cta/del-cta.zip why cant you compare your code with the code given in tutorial. Commented Oct 20, 2015 at 11:57
  • there no error... i want its in the way, when time ends its redirect to another page Commented Oct 20, 2015 at 12:12

1 Answer 1

1

Try this - gleaned from the source:

FIDDLE

$('#countdowntimer').countdown('<?php $date = strtotime("+1 day"); echo date('Y/m/d', $date); ?> 14:30:00')
  .on('update.countdown', function(event) {
      $(this).html(event.strftime(''
        + '%H Hours '
        + '%M Minutes '
        + '%S Seconds'
      ));
  })
  .on('finish.countdown', function(event) { 
      location.replace("someurl"); 
  });
Sign up to request clarification or add additional context in comments.

14 Comments

So look in the console to see why not
No, JS console - F12. I missed a left ) - it works now. See the jsfiddle.net/mplungjan/mncmnmqv - but scroll all the way down for the relevant code
<?php $date = strtotime("+1 day"); echo date('Y/m/d', $date); ?> after entering the script not working
Please show me what it translate to on the client - you ARE running this through the PHP server process?
Yes, it seems to work for me - I am of course not going to sit and watch it for 26 hours :) So are we done? If you change the alert to the location.replace and put in your URL instead of someurl, then it should work. I see $('#countdowntimer').countdown('2015/10/21 19:32:00')
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.