PHP and Javascript seconds problem

5 replies
<?php
if($endtime <= time()) {
echo "<script type=\"text/javascript\">
function changedetails() {
alert(\"Hello World!\");
}
</script>" . "<script type=\"text/javascript\">
changedetails();
</script>";
}
else {
$timeleft = $endtime + 1 - time();
echo "<script type=\"text/javascript\">
var trainleft = " . $timeleft . ";
function changedetails() {
var timeh = Math.floor(timeleft / 3600);
var timem = Math.floor((timeleft - (timeh * 3600)) / 60);
var times = Math.floor(timeleft - (timeh * 3600) - (timem * 60));
if(timeleft < 0) {
window.location = \"index.php\"
}
if(times >= 10) {
if(timem >= 10) {
document.getElementById('" . $itemdiv . "').innerHTML = timeh + \":\" + timem + \":\" + times;
}
else {
document.getElementById('" . $itemdiv . "').innerHTML = trainh + \":0\" + trainm + \":\" + trains;
}
}
else {
if(timem >= 10) {
document.getElementById('" . $itemdiv . "').innerHTML = timeh + \":\" + timem + \":0\" + times;
}
else {
document.getElementById('" . $itemdiv . "').innerHTML = timeh + \":0\" + timem + \":0\" + times;
}
}
timeleft = timeleft - 1;
timerg = setTimeout('changedetails()', 1000);
}
function timerg_clear() {
clearTimeout(timerg);
}
</script>" . "<script type=\"text/javascript\">
changedetails();
</script>";
}
?>
I have the above code, the timer is working fine. When the timeleft is 0 i want to refresh the page and ,but the problem is that the page is refreshing 10 - 20 times after finishing. Thanks for any help !
#javascript #php #problem #seconds

Trending Topics