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>
Raj
  • 31
  • 1
  • 8
  • what error you get...? is there any error in console.? https://www.mathewporter.co.uk/dev/del-cta/del-cta.zip why cant you compare your code with the code given in tutorial. – Tintu C Raju Oct 20 '15 at 11:57
  • there no error... i want its in the way, when time ends its redirect to another page – Raj Oct 20 '15 at 12:12

1 Answers1

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"); 
  });
mplungjan
  • 169,008
  • 28
  • 173
  • 236
  • So look in the console to see why not – mplungjan Oct 20 '15 at 12:17
  • No, JS console - F12. I missed a left `)` - it works now. See the http://jsfiddle.net/mplungjan/mncmnmqv/ - but scroll all the way down for the relevant code – mplungjan Oct 20 '15 at 12:25
  • after entering the script not working – Raj Oct 20 '15 at 12:59
  • Please show me what it translate to on the client - you ARE running this through the PHP server process? – mplungjan Oct 20 '15 at 13:25
  • 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')` – mplungjan Oct 20 '15 at 14:16
  • its not working when we put the php inside the script. – Raj Oct 20 '15 at 14:21
  • What script? It cannot live in a .js file unless the .js file is served as a PHP file - PS: I am told that 2015/10/21 19.32 is in 3 hours.. That is incorrect – mplungjan Oct 20 '15 at 14:22
  • I do not understand. This is not a PHO question. The code I provided works if the PHP returns `yyyy/mm/dd hh:mm:ss` - if it does not, it will not work. What does `' 14:30:00'` show in the source of the page? – mplungjan Oct 20 '15 at 14:38
  • Yes and what is the issue other than the date is not utc when you store it? – mplungjan Oct 20 '15 at 15:50
  • DId you see my example in the fiddle? Do you have any errors in the console? What does "not working" mean? Nothing happens when the code reaches 1? Are you using the same version of the plugin as I am? – mplungjan Oct 20 '15 at 16:42
  • I don't have any error. which version are you using? – Raj Oct 20 '15 at 16:48
  • The one from github - copy it from my fiddle – mplungjan Oct 20 '15 at 16:50
  • you code is working, i have a question. How we can pull the server time and set a time zone – Raj Oct 20 '15 at 17:17
  • Read this and possibly use my date part from my fiddle http://stackoverflow.com/questions/9755911/send-php-date-to-javascript-date-format – mplungjan Oct 20 '15 at 17:21