Page 24 - LoudOffice_Guide-to-HTML_Part-II_Advanced.PDF
P. 24
summary, then, what we refer to as "JavaScript" is actually made up of JavaScript, the
language, and the DOM, or object model that JavaScript can access.
Because Microsoft's Document Object Model, as seen in MSIE 4 and 5 versus Netscape 4.x,
is the more advanced, MSIE is often the browser of choice for intranet developers who wish
to author advanced web-based applications. Its more articulate DOM allows the JavaScript
author much finer control in modifying aspects of the web page and creating flexible user
environments.
Below is a (rather amateurish) diagram of the DOM:
Properties
The properties of any object in the DOM can be accessed with a simple notation:
w i n d o w . d o c u m e n t . o b j e c t . If for instance, your document had a form named
i n p u t F o r m , and a field in the form named t x t A d d r e s s , you could access that field with
the following notation: d o c u m e n t . i n p u t F o r m . t x t A d d r e s s . Later, when we study form
validation with JavaScript, you’ll see where this is especially useful.
Event Handlers
JavaScript programs are typically event-driven. Events are actions that occur on the Web
page, usually as a result of something the user does, although not always. For example, a
button click is an event, as is giving focus to a form element; resizing the page is an event,
or submitting a form. It is these events that cause JavaScript programs to spring into
action.
An event is the action that triggers an event handler. The event handler specifies which
JavaScript code to execute. Often, event handlers are placed within the HTML tag that
creates the object on which the event acts:
< t a g a t t r i b u t e 1 a t t r i b u t e 2 o n E v e n t N a m e = " j a v a s c r i p t c o d e ; " >
LoudOffice.com Guide to HTML – Part II Page 24