Click here to Skip to main content
15,902,299 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here's my code
HTML
<br /><code><input name="time" type="text" value="<?php date('g:i:s A M, d Y')
?>" onload="setinterval(1000)"></code><br />{
What I'm trying to do is make the input code refresh every second, so it works like a normal clock} and {what It's doing is just staying like: "[8:40:16 PM Jul 25, 2013]" and not auto-updating.} Thank you in advance for your answers!
Posted
Updated 25-Jul-13 15:07pm
v3
Comments
Mohibur Rashid 25-Jul-13 21:49pm    
You haven't got anything right here.
1. You haven't got how client and server code work
2. You haven't got how setinterval or javascript work

first clear up your head about how php work and how javascript work then you will get around

First off the PHP part of the page is only fired once (when the page is processed by the webserver) and is not actually in you htmlpage. So unless you want the whole page to reload you need to do it in a javascript.

What I would do is make an div tag with the clock element in it in your html-code like this:
HTML
<div id="clock"></div>


and build a javascript class to handle the actual clock:

JavaScript
StartUp();

function UpdateClock() {
    var clockElement = document.getElementById('clock');
    var time = new Date();
    var hours = time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds();
    var date = time.getMonth() + " " + time.getDate() + ", " + time.getFullYear();
    clockElement.innerHTML = hours + " " + date;
}

function StartUp() {
    intervalId = setInterval(UpdateClock, 1000);
}


And that should do it. The hours and date variable needs to be formated ofcourse, but the basic is there

WilyeECoyote
 
Share this answer
 
You can refer the script site http://www.scripts.com/java-scripts/clock-scripts/[^] for any kind of code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900