Automatic timer

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
valmerin
Forum Newbie
Posts: 6
Joined: Mon Nov 02, 2009 5:29 pm

Automatic timer

Post 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.
User avatar
Grizzzzzzzzzz
Forum Contributor
Posts: 125
Joined: Wed Sep 02, 2009 8:51 am

Re: Automatic timer

Post 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
valmerin
Forum Newbie
Posts: 6
Joined: Mon Nov 02, 2009 5:29 pm

Re: Automatic timer

Post by valmerin »

Ty for your response
Post Reply