Text Object
For each instance of an HTML <input type="text"> tag on a form, a
Text
object is created.
All Text objects are stored in the elements array of the corresponding form.
You can access a Text object by indexing this array - either by number (0
represents the first element in a form) or by using the value of the name
attribute.
The Text object's properties, methods, and events are
described below:
N: Netscape (including Mozilla when N6 or higher), IE: Internet Explorer, W3C:
World Wide Web Consortium (Internet Standard)
Properties
Syntax: object.property_name
Property |
Description |
N |
IE |
W3C |
accept |
Sets or returns a list of content types that the server
that processes this form will handle correct |
|
- |
Yes |
accessKey |
Sets or returns the keyboard key to access the text field |
|
4 |
Yes |
align |
Sets or returns the alignment of the text field according
to the surrounding text |
|
- |
Yes |
alt |
Sets or returns an alternate text to display if the browser
does not support text fields |
|
- |
Yes |
defaultValue |
Sets or returns the initial value of the text field |
2 |
3.02 |
Yes |
disabled |
Sets or returns whether or not the text field should be
disabled |
6 |
5.5 |
Yes |
form |
Returns a reference to the text field's parent form |
2 |
3.02 |
Yes |
id |
Sets or returns the id of the text field (In IE 4 this
property is read-only) |
|
4 |
No |
maxLength |
Sets or returns the maximum number of characters in the
text field |
6 |
4 |
Yes |
name |
Sets or returns the name of the text field |
2 |
3.02 |
Yes |
readOnly |
Sets or returns whether or not the text field should be
read-only |
6 |
4 |
Yes |
size |
Sets or returns the size of the text field |
6 |
3.02 |
Yes |
tabIndex |
Sets or returns the tab order for the text field |
|
4 |
Yes |
type |
Returns the type of the form element. For a text object it will
always be "text" |
3 |
3.02 |
Yes |
value |
Sets or returns the value of the value attribute of the
text field |
2 |
3.02 |
Yes |
Methods
Syntax: object.method_name()
Method |
Description |
N |
IE |
W3C |
blur() |
Removes focus from the text field |
2 |
4 |
Yes |
click() |
Simulates a mouse-click in the text field |
|
4 |
No |
focus() |
Sets focus on the text field |
2 |
3.02 |
Yes |
select() |
Selects and highlights the entire text that is in the text
field |
2 |
4 |
Yes |
Events
Syntax: object.event_name="someJavaScriptCode"
Event |
Description |
N |
IE |
W3C |
onBlur |
Executes some code when the text field loses focus |
2 |
4 |
|
onChange |
Executes some code when the text field loses focus and its
value has altered |
2 |
3.02 |
|
onClick |
Executes some code when the user clicks the left mouse
button in the text field |
|
4 |
|
onFocus |
Executes some code when the text field gets focus |
2 |
3.02 |
|
onKeyDown |
Executes some code when a key is pressed in the text
field |
4 |
4 |
|
onKeyPress |
Executes some code when an alphanumeric key is pressed in the text field |
4 |
4 |
|
onKeyUp |
Executes some code when a key is released in the text field |
4 |
4 |
|
onSelect |
Executes some code when the current selection is changed in
the text field |
2 |
3.02 |
|
onSelectStart |
Executes some code when some text in the text field is
selected |
|
4 |
|
|