home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

HTML 4.0 Sourcebook
(Publisher: John Wiley & Sons, Inc.)
Author(s): Ian S. Graham
ISBN: 0471257249
Publication Date: 04/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


Using META to Specify A Default Script Language

If neither TYPE nor LANGUAGE is given, then the browser needs to guess at the language used by the document script. To avoid the possible confusion that may arise from this process, an author can use a META element to specify the default scripting language in a document. The form is:

<META HTTP–EQUIV=“Content–Script–type” CONTENT=“type/subtype”>

where type/subtype is the MIME type of the default document scripting language. Note that this format indicates that the default script type can also be indicated by an HTTP server response header field of the form:

Content–script–type: type/subtype

See Chapter 9 for more information about HTTP headers and the HTTP protocol.

Script Interaction with HTML Elements

Scripting languages become much more dynamic when they are bound to user input elements. In HTML, the basic user input elements are the anchor element A and the various FORM elements. Both JavaScript and VBScript provide bindings to these elements via the event handlers listed in Table 7.5—these event handlers are triggered by the events described in the table. For example, an onClick event can be triggered when a hypertext link is “selected” (clicked), while the onLoad event is triggered whenever a document or frame is loaded onto the display.

Event handlers are attached to specific elements via special event handling attributes. These attributes have names matching the events they handle (the attribute names are case insensitive) and take as their value the function that should be invoked when the event takes place. Consider, for example, the following markup:

<INPUT TYPE=“button” NAME=“butt1” VALUE=“foo”
       ONCLICK=“alert(’Uh oh –– you pressed the Foo Button!’ );”>

The ONCLICK attribute binds this button (named “butt1”) to the indicated JavaScript—here a simple alert pop–up window. When the user presses this button, the onClick event is triggered, and the browser will pop up an alert window containing the given message string.

To support client–specific form processing and user interaction, Netscape introduced a TYPE=“button” INPUT element. This is used for client–side actions only—the name and value associated with a TYPE=“button” element are never sent with the form data when a FORM is submitted to a remote server. This is illustrated in Figure 7.43, which shows a FORM containing two INPUT elements: one of TYPE=“button,” (taken from our previous example) and the other of TYPE=“submit.”

Figure 7.44 shows the document displayed after the user has selected the button labeled “foo.” This button is tied by the onClick event handler to the JavaScript alert() function, so that pressing this button causes the visible pop–up alert menu. If, instead, the user presses the submit button, the accessed URL is (omitting the leading part of the URL)

..../cgi/prog.pl?submit=Submit+It%21

which contains only the encoded data from the TYPE=“submit” button—the name and value from the TYPE=“button” element are absent.


Figure 7.43 Example HTML document illustrating the TYPE=“button” input element and event handling. The display of this form by Internet Explorer 3 is shown in Figure 7.44.

<HEAD><TITLE>
Scripting Test</TITLE></HEAD>
<BODY>
<H2>Buttons and More Buttons</H2>
<BLOCKQUOTE>
<FORM ACTION=“/cgi/prog.pl” METHOD=“get”>
  <H3> A Simple FORM Example</H3>
  <INPUT TYPE=“button”
     NAME=“butt1” VALUE=“foo”
     ONCLICK=“alert(’Uh oh –– you pressed the Foo Button!’ );” >
   –– <B>The FOO BUTTON!</B><BR>
  <INPUT TYPE=“submit” NAME=“submit” VALUE=“Submit it!”>
</FORM>
</BODY></HTML>


Figure 7.44  Display, by the Internet Explorer 3 browser, of the document listed in Figure 7.43. Note the JavaScript alert window displayed as a result of clicking on the button labeled “foo.”

HTML Elements and Event Handlers

With Netscape Navigator 4 and Internet Explorer 4, there are 12 commonly supported event handlers (listed in Table 7.5) and 19 different HTML elements that accept event handling attributes. However, only a few event handlers are appropriate for any given element—for example, the onUnload event, triggered when the user leaves document, is irrelevant to the AREA (client–side imagemap data) element, but appropriate to BODY and FRAMESET. To help keep track of which handlers go where, Table 7.6 lists elements that take event handlers, alongside the supported handler types. Note that support for these handlers may be buggy, or nonexistent, depending on the browser. Some common version–specific limitations are indicated in the table captions, but more definitive information is found in the book JavaScript, The Definitive Guide, by David Flanagan.

Internet Explorer 4 supports all these event handlers, plus many others that will be discussed later, in the section titled “Advanced Scripting and the Document Object Model.”

Dynamic Scripts

As mentioned, HTML output generated by scripts is static—once it is displayed on the page, it can in general only be modified by erasing the page and starting again. More dynamic interaction is possible using FORM text–level elements—script programs can dynamically update the value content of INPUT TYPE=“text” and TEXTAREA elements (they can actually modify the content of any VALUE attribute). This allows for auto–tabulating forms (for example, summing a column of elements, as in a spreadsheet) or dynamic generation of form field data using data derived from user input or other sources.


Table 7.5 Commonly Supported HTML Event Handling Attributes. Italicized event handlers were introduced in Netscape Navigator 3. These event handlers are supported by Netscape Navigator 3 and 4 and also by Internet Explorer 3 and 4. See also Table 7.6.

Attribute Description
onAbort Triggered when loading of images is aborted, for example by the user pressing the “Stop” button. This is relevant only for IMG elements.
onBlur Triggered when the associated form input element loses focus (i.e., the user selects text outside the element or selects another input element).
onChange Triggered when a form element both loses focus and has been modified (for example, by user–input of text, or by selecting a button).
onClick Triggered when a form–element button, or a hypertext link, has been selected (“clicked”).
onError Triggered when there is a problem loading an image, as when the image file or other reference is invalid or corrupted.
onFocus Triggered when a form input element is selected, usually by clicking the mouse button within the element or by using the tab key to advance to a new item.
onLoad Triggered when the document is loaded.
onMouseOut Triggered when the associated hypertext link is deselected (e.g., the mouse moves off the link).
onMouseOver Triggered when the cursor is moved onto the associated hypertext link.
onReset Triggered when a form reset button is pressed.
onSubmit Triggered when a form is submitted.
onUnload Triggered when the document is unloaded (e.g., the user selects to move to another page)


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.