HTML and CSS Reference
In-Depth Information
The
text
Object.
The
text
object represents the HTML text field
<input type=“text”>
and also has name and value fields. To reference a text field from JavaScript, go down
the document tree, starting at the
document
, then to the
form
, and then the
text
element.
To get a value in the text field, for example, you would use the following syntax:
document.form1.textbox1.value,
where
form1
is the name of the form and
textbox1
is the name of the text field. Shown in
Figure 11.25 is the JavaScript object hierarchy for the
text
object. Table 11.9 lists its
properties and Table 11.10 lists its methods.
window
document
form
text
Figure 11.25
The
text
object within the JavaScript hierarchy.
Table 11.9
Properties of the
text
Object
Property
What It Describes
accessKey
By default, pressing an access key sets focus to the text object. The
object receives focus when the user simultaneously presses the Alt key
and the access key assigned to an object.
alt
Sets or returns alternate text to display if a browser does not support
text fields.
defaultValue
The value assigned to the
value
attribute, and the default value the user
sees in the textbox when it first appears.
disabled
Sets or returns whether or not a text field should be disabled.
form
The name of the form where the textbox is defined.
id
Sets or returns the
id
of a text field.
name
The name used to reference the textbox.
Continues