please dont rip this site

JavaScript: The Definitive Guide

Previous Chapter 21
JavaScript Reference
Next
 

Element Object

Name

Element Object---a form element

Availability

Navigator 2.0, Internet Explorer 3.0; enhanced in Navigator 3.0

Synopsis

form.elements[i]
form.name

Properties

checked

A read/write Boolean that indicates the selection state of form elements that can appear "checked" or "unchecked."

defaultChecked

A read-only Boolean that specifies the default state of a form element that can be "checked." This value is specified by the CHECKED attribute of the HTML tag that creates the element, and its value is used when the form is reset.

defaultValue

A read-only string that specifies the default value for a form element. For elements that display text, this property specifies the initial value displayed, and the value displayed after the form is reset. This property corresponds to the HTML VALUE attributed.

form

A read-only reference to the Form object that contains this element.

length

For the Select form element, this property specifies the number of options or choices (each represented by an Option object) that are contained within the options[] array of the element.

name

A read-only string, specified by the HTML NAME attribute, that specifies the name of this element. This name may be used to refer to the element, as shown in the synopsis above.

options[]

For the Select form element, this array contains Option objects that represent the options or choices displayed by the Select object. The number of elements in the array is specified by the length property of the Select element.

selectedIndex

For the Select form element, this integer specifies which of the options displayed by the Select object is currently selected. In Navigator 3.0, this property is read/write. In Navigator 2.0 and Internet Explorer 3.0, it is read-only.

type

A read-only string property, available in Navigator 3.0, that specifies the type of the form element.

value

A string property that specifies the value to be sent to the server for this element when the form that contains it is submitted.

Methods

blur()

Remove keyboard focus from the element.

click()

Simulate a mouse-click on the form element.

focus()

Give keyboard focus to the element.

select()

For form elements that display editable text, select the text that appears in the element.

Event Handlers

onblur()

Invoked when the user takes keyboard focus away from the element.

onchange()

For form elements that are not buttons, this event handler is invoked when the user enters or selects a new value.

onclick()

For form elements that are buttons, this event handler is invoked when the user clicks or selects the button.

onfocus()

Invoked when the user gives keyboard focus to the element.

Description

Form elements are stored in the elements[] array of the Form object. The contents of this array are Element objects, which represent the individual buttons, input fields and other controls that appear within the form. Strictly speaking, all elements within a form are represented by Element objects. It is often more convenient, however, to consider these object to have the type of the form element they represent. Thus, in this book we often refer to Button objects, Text objects, Select objects, and so on. This reference page describes the general behavior of form elements. Specific behaviors for form elements are described on their own pages.

The Element object defines quite a few properties, methods, and event handlers, but not all of them are functional for each type of form element. For example, the Button object triggers the onclick() event handler, but not the onchange() handler, while the Text object triggers onchange() but not onclick(). The following figure shows all of the form elements and the properties associated with them.

Figure 21.1: Form elements and their available properties

[Graphic: Figure 21-1]

In general, there are two broad categories of form elements. The first is the buttons: Button, Checkbox, Radio, Reset, and Submit. These elements have an onclick() event handler, but not an onchange() handler. Similarly, they respond to the click() method but not the select() method. The second category are those elements that display text: Text, Textarea, Password and FileUpload. These elements have an onchange() event handler rather than an onclick() handler, and respond to the select() method but not the click() method.

The Select and Hidden elements are special, and do not fall into either of the above two categories. The Select element uses several properties of the Element object not used by any other objects, and, surprisingly does not use the value property--values for this object are supplied by the Option objects it contains. Finally, the Hidden element has no on-screen representation, so it does not have any event handlers nor does it respond to any methods.

Bugs

Unfortunately, the behavior of form elements varies on different platforms, at least in Navigator 2.0 and Navigator 3.0 (Internet Explorer 3.0 only runs on one platform). On Unix platforms, which run the X11 window system, only the text-entry form elements participate in keyboard navigation, and so the button elements and the Select element do not respond to the blur() and focus() methods nor do they invoke the onblur() and onfocus() event handler. Also, on Unix systems, the Text element is the only one that responds to the select() method. On Windows platforms, on the other hand, all form elements are fully "wired in," and they all respond as noted in the table.

See Also

"Button", "Checkbox", "FileUpload", "Form", "Hidden", "Password", "Radio", "Reset", "Select", "Submit", "Text", "Textarea"


Previous Home Next
Document.writeln() Book Index Element.blur()

HTML: The Definitive Guide CGI Programming JavaScript: The Definitive Guide Programming Perl WebMaster in a Nutshell

file: /Techref/language/java/script/definitive/refp_97.htm, 13KB, , updated: 2019/10/14 15:00, local time: 2024/11/30 02:43,
TOP NEW HELP FIND: 
3.128.171.192:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://massmind.org/Techref/language/java/script/definitive/refp_97.htm"> [Chapter 21] Reference: Element</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to massmind.org!

 

Welcome to massmind.org!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .