spacer

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

home / programming / professional / chap6/ 1 To page 1To page 2To page 3current pageTo 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 elements Object

When you access a form, you usually actually want to access one or more of its elements. In itself that's easy. Each form object has an elements[] array object as a property, which works in the same way as the forms[] array. Once again document.forms[0].elements is only an array – to actually access the element of your choice, you must specify it. For example, to access the input field named input1 in the first form, we can use any of these four references:

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

There are several types of form elements, and it's best to divide them into four groups:

These are some of the properties and methods of individual form element objects.


Property

Form Elements Applicable To

Read/write

Description

checked

Checked elements

read/write

Returns a Boolean that is true when the element is checked, and false when it isn't.

disabled

All elements, except hidden

read/write

Returns a Boolean. When set to true, the form field is disabled: the user cannot change anything.

Supported by IE 4+, Netscape 6+, Opera 6+, iCab, and Konqueror.

form

All elements

read-only

Returns a reference to the form the element is a part of.

length

Select

read-only

Returns the number of options in the element

name

All elements

read-only

Accesses the name attribute of the element

selectedIndex

Select

read/write

Returns the index number of the currently selected option

type

All elements

read-only

Gives the type of the element. Its value is the same as the type attribute of the form field, except that:

1) <select> elements can be of two types: select-one (if attribute multiple is set to false) or select-multiple

2) A <textarea> element has type textarea

value

All elements

read/write.

read-only for file upload fields

Accesses the value attribute of the element. If you set the content of a text element, it shows this value.

Older browsers don't recognize the value of a select box.


Method

Form Elements Applicable To

Description

blur()

All elements, except hidden

Takes  the focus away from the element.

click()

All elements except text

Simulates  a mouse click on the element.

focus()

All elements, except hidden

Gives  the element focus.

select()

Text elements, except hidden

Selects all text in the element.

 


home / programming / professional / chap6/ 1 To page 1To page 2To page 3current pageTo 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