php - Javascript timer not stopping -


the following script counts down won't stop counting when reaches end time. when reaches zero, start again 60:00 0 (another hour). when skip part

$time = str_replace(' ', 't', $db[time]);  

and this:

var end = new date('<?=$db[time]?>'); 

the counter stopping correctly, counter wont work @ ie or firefox in chrome.

anyone know how stop counter:s thanx!

$db[time] = timestamp field in database (2013-10-03 11:32:39)  

the script:

$time = str_replace(' ', 't', $db[time]); 

java script

<script> var end = new date('<?=$time?>'); var _second = 1000; var _minute = _second * 60; var _hour = _minute * 60; var _day = _hour * 24; var timer;  function showremaining() {     var = new date();     var distance = end - now;     if (distance < 0) {          clearinterval(timer);         document.getelementbyid('countdown').innerhtml = 'its time!</font><br><br>';                         return;     }     var days = math.floor(distance / _day);     var hours = math.floor((distance % _day) / _hour);     var minutes = math.floor((distance % _hour) / _minute);     var seconds = math.floor((distance % _minute) / _second);       document.getelementbyid('countdown').innerhtml = '<font color="orange">' + minutes + ':';     document.getelementbyid('countdown').innerhtml += '<font color="orange">' + seconds + ' minutes</font>'; }  timer = setinterval(showremaining, 1000);  </script> 

i suggest use

var countinterval = setinterval(function() { countdown(secondsremaining); },1000) instead.

this way won't have play around date or time objects. keep count inside countdown() , clearinterval(countinterval) once reach 60.


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -