I have been trying for half a day to loop this countdown function. I do not want to create different countdown. How do I go about looping it? Please take note that this is a countdown timer with interval of 1 second. My site is here http://jian.comoj.com/
<script type="text/javascript">
setInterval('countdown()',1000);
function countdown(){
var now = new Date();
var unix_now= now.getTime()/1000;
unix_now= Math.floor(unix_now);
var sec = <?php echo $end_time[0]; ?> - unix_now;
if(sec<=0){
clearInterval(stop);
}
var min = Math.floor(sec / 60);
var hour = Math.floor(min / 60);
hour %= 24;
min %= 60;
sec %= 60;
document.getElementById(0).innerHTML= hour+":"+min+":"+sec;
}
setInterval('countdown1()',1000);
function countdown1(){
var now = new Date();
var unix_now= now.getTime()/1000;
unix_now= Math.floor(unix_now);
var sec = <?php echo $end_time[1]; ?> - unix_now;
if(sec<=0){
clearInterval(stop);
}
var min = Math.floor(sec / 60);
var hour = Math.floor(min / 60);
hour %= 24;
min %= 60;
sec %= 60;
document.getElementById(1).innerHTML= hour+":"+min+":"+sec;
}
setInterval('countdown2()',1000);
function countdown2(){
var now = new Date();
var unix_now= now.getTime()/1000;
unix_now= Math.floor(unix_now);
var sec = <?php echo $end_time[2]; ?> - unix_now;
if(sec<=0){
clearInterval(stop);
}
var min = Math.floor(sec / 60);
var hour = Math.floor(min / 60);
hour %= 24;
min %= 60;
sec %= 60;
document.getElementById(2).innerHTML= hour+":"+min+":"+sec;
}
</script>
You need to put
setIntervalinside the countdown functions too. Something like recursive calling.