Saturday, December 6, 2008

What is the DOM?

The Document Object Model, or DOM, is an interface to allow programs and scripts to update content, structure, and style of documents dynamically. It is platform- and language-neutral. The DOM is not HTML nor is it JavaScript. It is something like the glue that binds them together.

DOM Level 0

The DOM level 0 is a mix of HTML functions that have not been formally specified that allow scripting languages to interact with Microsoft Internet Explorer 3.0 and Netscape Navigator 3.0. This basically means that if a DHTML page is compliant with DOM level 0 it should work reliably even in fairly old browsers.

The base structure of the DOM level 0 is the document master container. This refers to the entire document, and all elements within it. It is referenced as:

document

Because the DOM level 0 is very basic, it only allows the developer to manipulate items on the page that already have some level of interactivity, i.e. forms. It is possible to reference other items in a Web document, but most browsers don't support much interactivity with them at level 0.

Referencing Forms

There are three ways to reference a form control using DOM level 0:

by name or id
This is the easiest way to reference a form control, as you can clearly see in the XHTML which form you a referring to. For example, this form is named "form1":

<form name="form1" id="form1">...</form>

It would be referenced in the DOM as:

document.form1

Then if you wanted to reference an element within the form, you would name it as well:

document.form1.fname

references

<input type="text" name="fname" />

in the above form.

by number
Each form, and element within the form, is given a number in an array, starting with 0. They are numbered starting with the first

element found in the flow of the document. So, to reference the second form on the page:

document.form[1]

Then, to reference the second form element within the second form:

document.form[1].element[1]

a combination of both
It is possible to use any combination of number or name to reference a form or form element within the document:

document.form[0].fname
document.form1.element[3]

Labels: ,



0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home