spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / professional / chap6/ 1 To page 1To page 2current pageTo page 4To page 5To page 6To page 7
[previous] [next]

The Web Professional's Handbook: Document Object Models

Finance Developer (IL)
Next Step Systems
US-IL-Chicago

Justtechjobs.com Post A Job | Post A Resume
Developer News
OpenOffice 3.2 Lands Amid Critical Changes
Red Hat, IBM Firmly in KVM Virtualization Camp
Red Hat Talks Up Open Source Cloud Plans


The forms Object

The document.forms[] array object holds references to all the <form> elements in the page. To access a single form, you need to specify it in one of two ways:

For example, suppose you have two forms:

<form name="firstform">
  <input name="yourname" />
</form>
<form name="secondform">
 <input name="nickname" />
</form>

You can access the first form in two ways:

document.forms[0]
document.forms['firstform']

Similarly, these two DOM references access the second form:

document.forms[1]
document.forms['secondform']

You can even leave out the forms[] array entirely: document.firstform is a correct DOM reference and all browsers will access the form. The disadvantage is that your scripts become harder to read, which may be a problem when they need to be updated. It's better to fully write document.forms['firstform'].

IE even understands the call firstform, without any reference to the document. However, as we saw before, other browsers may have trouble with this syntax.

Here are some of the properties and methods of individual form objects.

Property

Read/write

Description

action

read/write

Accesses the action attribute of the form.

length

read-only

Gives the number of elements in the form.

method

read/write

Accesses the method attribute of the form.

name

read-only

Accesses the name attribute of the form.

target

read/write

Accesses the target attribute of the form.


Method

Description

reset()

Resets  all elements of the form to their default values.

submit()

Submits the form . If you use this method, any onsubmit event handler is ignored.

For example, these properties and methods can be used to POST a form's data to script2.pl, like this:

document.forms['firstform'].method  = 'POST';
document.forms['firstform'].action = 'script2.pl'
document.forms['firstform'].submit()


home / programming / professional / chap6/ 1 To page 1To page 2current pageTo page 4To page 5To page 6To page 7
[previous] [next]


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

webref The latest from WebReference.com Browse >
Search Engine Optimization: Selecting and Embedding Keywords · Are Google's Language Translation Web Services Ready for Prime Time? · Installing and Using Meeplace, the Business Review CMS
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
IBM DB2 10 for z/OS: Justifying the Upgrade · Living La Vida Colo: Choosing the Right Colocation Facility · FTC Concerns over Social Media Privacy Linger

Created: March 11, 2003
Revised: March 11, 2003

URL: http://webreference.com/programming/professional/chap6/1