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

Vice President of Risk Technology - READY TO HIRE! (NYC)
Next Step Systems
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume
Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs


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]

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint

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

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