I'm trying to make it so that when the stime function reaches 00:00, the div id "refresh" will refresh the content inside..
<script type="text/javascript">
var currenttime = '<? print date("F d, Y H:i:s", time())?>'
var montharray=new
var serverdate=new Date(currenttime)
function stime(){
var fiveMinutes = 5 * 60 * 1000;
var untilNext = fiveMinutes - (serverdate % fiveMinutes);
var timer=(untilNext / 1000)
var minutes= "0" + Math.floor(untilNext / 1000 / 60)
var seconds= "0" + (timer - minutes * 60)
document.getElementById("stime").innerHTML=minutes.substr(-2)+":"+seconds.substr (-2)
}
window.onload=function(){
setInterval("stime()", 1000)
}
</script>
<?php
echo '<div id="refresh">Health: <span style="float:right" id="stime"></span></div><br />';
?>
Is it possible with that function, to make another function that would refresh the div when the stime function reaches 00:00 ?
Make your setInterval like this:
window.onload=function(){
setInterval(stime, 1000)
}
<script type="text/javascript">
var currenttime = '<? print date("F d, Y H:i:s", time())?>';
var montharray=new Array();
var serverdate=new Date(currenttime);
function doRefresh(){
//code to refresh or ajax.
}
function stime(){
var fiveMinutes = 5 * 60 * 1000;
var untilNext = fiveMinutes - (serverdate % fiveMinutes);
var timer=(untilNext / 1000);
var minutes= "0" + Math.floor(untilNext / 1000 / 60);
var seconds= "0" + (timer - minutes * 60);
var timeString = minutes.substr(-2)+":"+seconds.substr(-2);
document.getElementById("stime").innerHTML=timeString;
if(timeString==="00:00")
{
doRefresh();
}
}
window.onload=function(){
setInterval("stime()", 1000);
}
</script>
<?php
echo '<div id="refresh">Health: <span style="float:right" id="stime"></span></div><br />';
?>
try to end statements with ";". it would be good to use indent.(Increase readablity). Please don't leave variables hanging. var montharray=new