Categories:

The object model of JavaScript

Before we start diving in head first, lets just a close look at the object concept of JavaScript, which will all tie in with accessing forms.

JavaScript is a language of objects, and objects are something you should not be afraid of. A simple example of an object is the document object, which allows us to access various aspects of a document, such as background color, referrer etc. JavaScript contains many objects, each representing one component of the web page.

Think of an object as a "tool" that contains properties and methods, allowing it to do things. Lets use a typical example. In real life, a car would be the object, the leather seats, power steering would be the properties, and the car's ability to move around is the object's method. In JavaScript, its just like that. However, properties of one object may itself be another object, which in turn contains other properties. This is important, and I will talk a little more about this. The below is the JavaScript Object tree, which lists, in order, each object, and also, the precedence of the objects.

The JavaScript Object Tree

objhier.gif (3174 bytes)
IMPORTANT: THIS IMAGE WAS TAKEN FROM THE NETSCAPE JAVASCRIPT AUTHORING GUIDE. FULL CREDIT FOR THE ABOVE IMAGE GOES THERE.

If you want to access something further down below the tree from the object "window", you use the (dot) operator to specify your choice. For example, if you want to write something to the current document, you would do something like the following: window.document.write("Hola") However, its important to understand that the "window" part is omitted for most references. The reason why you could write document.write("Hola")instead of window.document.write("Hola")is because JavaScript assumes you are talking about the current window. Lets have a look at how form objects are accessed.