Logo

1.6K views Asked 18 Mar 2020 in PHP
3
How can the timer be coded to reset automatically after 30 seconds and repeat the countdown?
User umgbemena (210 Points)


You can use meta referesh . The meta referesh will refresh the page after 30 seconds and the countdown timer will be start automatically .  –  shakti 18 Mar 2020
Add comment
1 Answer
1
shakti (9.4K Points)

answered 18 Mar 2020

I commented and suggested using a meta refresh to reset the countdown timer automatically. When countdown timer time ended then meta refresh reshes the whole page and the countdown timer starts from 30 seconds. This process will continue again and again and never stop. It's a method to reset the countdown clock timer using Meta refresh and also you can set any value using PHP programming. 

<!DOCTYPE html>
<html>
<head>
<title> Refresh countdown timer automatically</title>
</head>
<body>
<?php 
$phpvar="30"; 
?> 
<script>
function countDown(secs,elem) {
var element = document.getElementById(elem);
element.innerHTML = "Timer: "+secs+" seconds";
if(secs < 1) {
clearTimeout(timer);
element.innerHTML += '<meta http-equiv="refresh" content="0; url= ">';
}
secs--;
var timer = setTimeout('countDown('+secs+',"'+elem+'")',1000);
}
</script>
<div id="status"style="font-size:30px;"></div>

<script> countDown(<?php echo $phpvar; ?>,"status");</script>

</body>
</html>

 


Your Answer
×
Login Required

You must login to continue.

Login Google Login with Google
Register