Learning Javascript: Displaying self updating time on a webpage
<html>

<body>

<div id="date">

</div>

<script language="JavaScript">

//Create a function to call later.
function update() {

//This variable equals the computers date.
time = Date();

//Change the inside html "date" to the variable time.
document.getElementById('date').innerHTML = time;

//update this function in 0 time.
setTimeout("update()", 0);

}

//call our function to start.
update();

</script>

</body>

</html>

Easy eh? Here it is without comments so you can copy & paste without need to edit:

<html>

<body>

<div id="date">

</div>

<script language="JavaScript">

function update() {
time = Date();
document.getElementById('date').innerHTML = time;
setTimeout("update()", 0);

}

update();

</script>

</body>

</html>

And thats it hope it becomes useful somehow. More programming tutorials coming soon, please feel free to comment on this tutorial!
Number of comments: 2
0  
2 Dáithí   (2010-04-06 10:17 PM)
Beautiful, simple, effective!

0  
1 James   (2010-01-05 6:05 PM)
I dont understand, ajax fully, -just wondering, does this need connection to update?

-Because it's not 'get'ing anything,

Or does it still need abit of bandwidth to display/update it?

Thanks...


Only registered users can add comments.
[ Ðåãèñòðàöè ÿ | Âõîä ]
» Making Money Online
PPC [1]
Payment Systems [1]
Follow Me:
  • freewebhoto on youtube
  • freewebhoto on blogspot
  • freewebhowto on delicious
  • freewebhowto on reddit
  • freewebhowto on twitter
  • freewebhowto on digg
Create a website for free