Team LiB   Previous Section   Next Section
Input Client-side JavaScript 1.0

a form input element Inherits From: Element

Synopsis

form.elements[i]
form.elements[name]
form.name

Properties

The Input object defines properties for each of the attributes of the HTML <input> tag, such as maxLength, readOnly, size, and tabIndex. In addition, it defines the following properties:

checked

A read/write boolean that specifies whether an input element of type "checkbox" or "radio" is checked (true) or not (false).

defaultChecked

A boolean that specifies whether an input element of type "checkbox" or "radio" is checked when first created or when it is reset to its initial state.

defaultValue

A string that specifies the text that appears in an input element of type "text" or "password" when it is first created or when it is reset to its initial state. For security reasons, this property does not affect input elements of type file.

form

A read-only reference to the Form object that contains the element. This property is defined for input elements of all types.

name

The name of this input element, as specified by the HTML name attribute. This property is defined for input elements of all types.

type

A string that specifies the type of the form element. This property mirrors the HTML type attribute. Legal values are listed in the following table; the default is text. Submit and Textarea objects also have a type property, with possible values select-one, select-multiple, and textarea. JS 1.1.

Type

Description

"button"

Push button

"checkbox"

Checkbox element

"file"

File upload element

"hidden"

Hidden element

"image"

Graphical form submit button

"password"

Masked text entry field

"radio"

Mutually-exclusive radio button

"reset"

Form reset button

"text"

Single-line text entry field

"submit"

Form submission button

value

The string value that is sent when the form is submitted. For input elements of type "text", "password", and "file", this is the editable text displayed in the element. You can set this property to change that displayed text. For input elements of type "button", "submit", and "reset", value is the label that appears in the button. For other types, the value string is not displayed. Note that for security reasons, the value property of elements of type "file" is usually read-only.

Methods

blur( )

Yields the keyboard focus and returns nothing. Defined for all element types except "hidden".

click( )

Simulates a mouse click on the form element and returns nothing. Defined for button element types: "button", "checkbox", "radio", "reset", and "submit".

focus( )

Takes the keyboard focus and returns nothing. Defined for all element types except "hidden".

select( )

Selects the text that appears in the element and returns nothing. Works for elements of type "text", "password", and "file". Also defined by the Textarea object.

Event Handlers

onblur

Invoked when the element loses keyboard focus. Defined for all element types except "hidden".

onchange

For text-entry elements of type "text", "password", and "file", this event handler is invoked when the user changes the displayed text and then transfers keyboard focus away from the element, signaling that text entry is complete. It is not invoked for each keystroke.

onclick

For button elements of type "button", "checkbox", "radio", "reset", and "submit", this event handler is invoked when the user clicks the button. Return false to prevent form submission or reset for elements of type "submit" and "reset", respectively.

onfocus

Invoked the element gains keyboard focus. Defined for all element types except "hidden".

See Also

Form, Option, Select, Textarea

    Team LiB   Previous Section   Next Section