i have this in php file
<body>
<span id="time"></span>
</body>
<?php $var0 = 1; ?>
and this in javascript
function startTimer(duration, display) {
var timer = duration, minutes, seconds;
setInterval(function () {
minutes = parseInt(timer / 60, 10)
seconds = parseInt(timer % 60, 10);
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;
if(minutes <= 0){
display.textContent = seconds + "s";
}else{
display.textContent = minutes + "m " + seconds + "s";
}
if (--timer < 0) {
timer = duration;
}
}, 1000);
}
window.onload = function () {
var fiveMinutes = 60 * <?php echo $var0; ?>,
display = document.querySelector('#time');
startTimer(fiveMinutes, display);
};
it works perfectly but i need to display this in a loop for example i have 2 variables and i want to display two times with new line .. or when i have n variables i got n new line with the time of the variables that will hold the information from database.. thank you
startTimer()twice for 2 variables? Or if you have multiple variables, why not try a for loop?<span>s dynamically each time you start a timer