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.

Platinum Edition Using HTML 4, XML, and Java 1.2
(Publisher: Macmillan Computer Publishing)
Author(s): Eric Ladd
ISBN: 078971759x
Publication Date: 11/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


anchor objects are also referenced using an object array—the anchors array. The only property of this object array, however, is the length property, which returns the number of elements in the array.

The form Object

The HTML form object is the primary way for Web pages to solicit different types of input from the user. JavaScript will often work along with HTML forms to perform its functions. The object model for HTML forms includes a wide variety of properties, methods, and events. If you use these with each form, JavaScript can manipulate and access those forms.

form Object Properties

Tables 19.4, 19.5, and 19.6 show some of the properties, methods, and events attached to HTML form objects. These can be used in JavaScripts—the properties and methods can be used to access or manipulate information and to perform certain functions, and the events can be used to trigger JavaScript functions related to the form itself. If a form is named Form1, for instance, the method document.Form1.submit() can be called in JavaScript to submit the form. On the other hand, if the Submit button calls a function in response to an onSubmit event, the submission of the form can be disabled if the function returns a false value. This is a good way to perform form validation within the Web browser and to allow submission of the form only if all fields are validated.

Note that the HTML form elements that can be included within the form, <INPUT>, <RADIO>, <CHECKBOX>, and other form tags, are also represented as objects and can be referenced by JavaScript. These form element objects are also properties of their parent form—they are discussed in the next section.

Table 19.4 Properties of the HTML form Object

Property What It Contains

name the value of the form’s NAME attribute
method the value of the form’s METHOD attribute
action the value of the form’s ACTION attribute
elements the elements array of the form
length the number of elements in the form
encoding the value of the form’s ENCODING attribute
target window targeted after submit for form response

Table 19.5 Methods of the HTML form Object

Method What It Does

reset() resets the form to its initial values
submit() submits the form

Table 19.6 Events of the HTML form Object

Event When It Occurs

onReset triggered when the <RESET> button is clicked or the reset() method is called
onSubmit triggered when the <SUBMIT> button is clicked or the submit() method is called

Using Objects to Manipulate Form Elements

A good place to use JavaScript is in forms; this is so because you can write scripts that process, check, and perform calculations with the data the user enters. JavaScript provides a useful set of properties and methods for text <INPUT> elements and buttons and the other form elements.

You use <INPUT> elements in a form to enable the user to enter text data; JavaScript provides properties to get the objects that hold the element’s contents as well as methods for doing something when the user moves into or out of a field. Table 19.7 shows some of the properties, methods, and events defined for <INPUT> form element objects.


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.