Automatic timer
Moderator: General Moderators
Automatic timer
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.
- Grizzzzzzzzzz
- Forum Contributor
- Posts: 125
- Joined: Wed Sep 02, 2009 8:51 am
Re: Automatic timer
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:
to have it as a countdown is just simple maths
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>
Re: Automatic timer
Ty for your response