Monday, November 19, 2007

How to work with the Java Script

How to work with the Java Script

To work with the Java Script

This Java Script code sample shows you how to use the simple Java Script to display the time and date obtained from the viewer’s operating system.

JavaScript sample:

          document.write("Your Local Time"),

          currtime = new Date();

          document.write("It is currently " + currtime + " where you live.")

    1. The document.write() method on the "Your Local Time" line writes an H1-formatted text string from the document to the screen of the browser.

    1. new Date() creates a new date object containing the long version of the current date from the viewer’s operating system. This object is assigned to currtime.

    2. The last line is output again to the browser’s screen using the document.write() method, with the embedded currtime variable set to the current time and date.

The result is shown as below.


No comments: