Browser Detection

The JavaScript Navigator object contains all information about the visitor's browser.

IMPORTANT! The version number is WRONG in IE 5.0 or later! Microsoft starts the appVersion string with the number 4.0. in IE 5.0 and IE 6.0!!! Why did they do that??? However, JavaScript is the same in IE6, IE5 and IE4, so for most scripts it is ok.

JScript Cookies

Click THIS LINK for a sample cookies demonstration

Form Validation

JavaScript can be used to validate input data in HTML forms before sending off the content to a server.

Form data that typically are checked by a JavaScript could be:

Check if Required Field is empty


Check if Filled-in Field has Valid Syntax


Animated Buttons

It is possible to use JavaScript to create animated images.
The trick is to let a JavaScript change between different images on different events.

Visit W3Schools!

Image Map

An image-map is an image with clickable regions.

A simple example can be found in XHTML/HTML_Notes2.htm

Planets Sun Mercury Venus

Move Mouse over a planet and its description appears here!

Timing Events

With JavaScript, it is possible to execute some code NOT immediately after a function is called, but after a specified time interval. This is called timing events.

It's very easy to time events in JavaScript. The two key methods that are used are:

Note: The setTimeout() and clearTimeout() are both methods of the HTML DOM Window object.


var t=setTimeout("javascript statement",milliseconds)
clearTimeout(setTimeout_variable i.e. t)

Example 1: var t=setTimeout("alert('3 seconds is up!')",3000)
Example 2:
Example 3: clearTimeout(tt)
Example 4:

JavaScript Create Your Own Objects

Objects are useful to organize information.

JavaScript has several built-in objects, like String, Date, Array, and more.
In addition to these built-in objects, you can also create your own.
An object is just a special kind of data, with a collection of properties and methods.
Properties are the values associated with the object.
Methods are the actions that can be performed on objects.


Create a Direct Instance of an Object

personObj=new Object()

The following adds the method eat() to the personObj:

Create a template of an object (Class)

function person(firstname,lastname,age,eyecolor){

  this.newlastname=newlastname -> methods are also added in the function

Notice that the template is just a function. Inside the function you need to assign things to this.propertyName. The reason for all the "this" stuff in is that you're going to have more than one person at a time (which person you're dealing with must be clear). That's what "this" is: the instance of the object at hand.

Instantiatinig from the object:
myFather=new person("John","Doe",50,"blue")
myMother=new person("Sally","Rally",48,"green")

Note that methods are just functions attached to objects. Then we will have to write the newlastname() function:
function newlastname(new_lastname){

The newlastname() function defines the person's new last name and assigns that to the person. JavaScript knows which person you're talking about by using "this.". So, now you can write: