PHP + JavaScript countdown echo 5 seconds / 1 second
I just figured out how to use javascript to echo a dynamic countdown for
my redirect page. I'm curious about how to echo "second" when only 1
second is left in the countdown, but how do I do it?
Here is my code:
<script>
var counter = 5;
setInterval (function()
{
counter--;
if(counter < 1)
{
window.location = 'login.php';
}
else
{
document.getElementById("count").innerHTML = counter;
}
}, 1000);
</script>
--
echo "<table><tr><td> You will be redirected in <div id=\"count\">5</div>
seconds.</td></tr></table>";
It echos "Redirecting in 5/4/3/2/1 seconds." OC as it is, I am bothered by
that S when the countdown reaches 1. Any help would be appreciated.
No comments:
Post a Comment