indiWiz.com
SiteSearch:
Jump:

Site Map | WizTools.org | jCraze Blog
Web Developer's Den!
Home : WDD : JavaScript
This Article...
Print Version
Add Comment
View Comments
JavaScript
The Bare Facts
Rollover Script
Script Windows
Status Message
Time Sensibility of JavaScript
JavaScript and Frames
Expandable Menus
Cursor Effects!
Regular Expressions Reference
JavaScript Screen Size
JavaScript HTMLize (Using Regular Expressions)
Java Script Dynamic Time Update
Sections

Commniquè
Sign Guestbook!
Read Guestbook!
MailMe!

JavaScript Dynamic Time Update

Long back, when I wanted to display Time in my website, the only code that I could get my had on were those displaying the time in a text form. But now with advancements in JavaScript specification, the following is possible:

The code? You need to have a HTML span element with id 'dt' (or whatever name you wish to give):

<span id="dt"></span>

Now write the code to add dynamic 'inner HTML' to this element:

<script language="javascript">

setInterval('dispDate()', 1000);

function dispDate(){
  myDate = new Date();
  document.getElementById('dt').innerHTML = myDate;
}

</script>

The setInterval() function calls the function dispDate() once in every 1000 milliseconds (1000 milliseconds = 1 second). And in this function we set the new Date in the layer 'dt'.

That's it folks!


User Comments

Add Comment

[Quick Stats: Number of main threads: 0, Number of sub-threads: 0]

Sign Guestbook | Who is Subhash?
The contents of this site are copyright© 2000-2008, indiWiz.com. All Rights Reserved.