Page 1 of 1
Automatic timer
Posted: Mon Nov 30, 2009 10:28 am
by valmerin
I want to create an automatic timer on a website that counts down in real time. I want it to count down without refreshing the whole web page. Could some one help me accomplish this please.
Re: Automatic timer
Posted: Mon Nov 30, 2009 10:46 am
by Grizzzzzzzzzz
Don't think this is accomplishable in PHP, at least it wouldn't be easy if it was.
You'd most likely have to use something else that runs browser side, such as Javascript
basic javascript auto-clock script can be found
here:
Code: Select all
<html>
<script language="Javascript">
setInterval("settime()", 1000);
function settime () {
var curtime = new Date();
var curhour = curtime.getHours();
var curmin = curtime.getMinutes();
var cursec = curtime.getSeconds();
var time = "";
if(curhour == 0) curhour = 12;
time = (curhour > 12 ? curhour - 12 : curhour) + ":" +
(curmin < 10 ? "0" : "") + curmin + ":" +
(cursec < 10 ? "0" : "") + cursec + " " +
(curhour > 12 ? "PM" : "AM");
document.date.clock.value = time;
}
</script>
<body>
<form name="date">
<input type="text" name="clock" style="border: 0px" value="">
</form>
</body>
</html>
to have it as a countdown is just simple maths
Re: Automatic timer
Posted: Mon Nov 30, 2009 11:37 am
by valmerin
Ty for your response