input (type="text") | NN 2 IE 3 DOM 1
The text object is a form control generated with an input element that has a type attribute set to "text". This object is the primary way of getting a user to enter single lines of text for submission to the server.
HTML Equivalent
    <input type="text">
Object Model Reference
    [window.]document.formName.elementName
    [window.]document.forms[i].elements[i]
    [window.]document.getElementById("elementID")
Object-Specific Properties

dataFld | dataSrc | defaultValue | form | maxLength
name | readOnly | size | type | value

Object-Specific Methods

createTextRange( ) | handleEvent[ ] | select( )

Object-Specific Event Handler Properties

Handler | NN | IE | DOM
onblur | 2 | 3 | 2
onchange | 2 | 3 | 2
onfocus | 2 | 3 | 2
onkeydown | 4 | 4 | n/a
onkeypress | 4 | 4 | n/a
onkeyup | 4 | 4 | n/a
onselect | 2 | 4 | 2

dataFld | NN n/a IE 4 DOM n/a
| Read/Write
Used with IE 4 data binding to associate a remote data source column name to a text object's value property. A datasrc attribute must also be set for the element. Setting both the dataFld and dataSrc properties to empty strings breaks the binding between element and data source. Works only with text file data sources in IE 5/Mac.
Example
    document.myForm.myText.dataFld = "price";
Value
Case-sensitive string identifier of the data source column.
Default
None.

dataSrc | NN n/a IE 4 DOM n/a
| Read/Write
Used with IE data binding to specify the ID of the page's object element that loads the data source object for remote data access. Content from the data source is specified via the datafld attribute. Setting both the dataFld and dataSrc properties to empty strings breaks the binding between element and data source. Works only with text file data sources in IE 5/Mac.
Example
    document.myForm.myText.dataSrc = "DBSRC3";
Value
Case-sensitive string identifier of the data source.
Default
None.

defaultValue | NN 2 IE 3 DOM 1
| Read-only
The default text for the text input element, as established by the value attribute.
Example
    var txtObj = document.forms[0].myText;
    if (txtObj.value != txtObj.defaultValue ) {
        ...
    }
Value
String value.
Default
None.

form | NN 2 IE 3 DOM 1
| Read-only
Returns a reference to the form element that contains the current element.When processing an event from this element, the event handler function automatically has access to the input element (as the event object's target or srcElement property). By reading the form property, the script can easily access other controls within the same form.
Example
    var theForm = evt.srcElement.form;
Value
form element object reference.
Default
None.

maxLength | NN 6 IE 4 DOM 1
| Read/Write
Indicates the maximum number of characters that may be typed into a text input element. In practice, browsers beep or otherwise alert users when a typed character would exceed the maxLength value. There is no innate correlation between the maxLength and size properties. If the maxLength allows for more characters than fit within the specified width of the element, the browser provides horizontal scrolling (albeit awkward for many users) to allow entry and editing of the field.
Example
    document.entryForm.myText.maxLength = 35;
Value
Integer value.
Default
Unlimited.

name | NN 2 IE 3 DOM 1
| Read/Write
This is the identifier associated with the form control. The value of this property is submitted as one-half of the name/value pair when the form is submitted to the server. Names are hidden from user view, since control labels are assigned via other means, depending on the control type. Form control names may also be used by script references to the objects. Despite the modern standards' preference for the id attribute, many browsers still require that a form control be assigned a name attribute to allow the control's value to be submitted.
Example
    document.orderForm.myText.name = "lastName";
Value
Case-sensitive string identifier that follows the rules of identifier naming: it may contain no whitespace, cannot begin with a numeral, and should avoid punctuation except for the underscore character.
Default
None.

readOnly | NN 6 IE 4 DOM 1
| Read-only
Specifies whether the form element can be edited on the page by the user. A form control that has a readOnly property set to true may still be modified by scripts, even though the user may not alter the content.
Example
    if (document.forms[0].myText.readOnly) {
        ...
    }
Value
Boolean value: true | false.
Default
false

size | NN 6 IE 4 DOM 1
| Read/Write
Roughly speaking, indicates the width in characters that the input box should be sized to accommodate. In practice, the browser does not always accurately predict the proper width. See details in the size attribute discussion for the input element in Chapter 8. There is no interaction between the size and maxLength properties for this object.
Example
    document.forms[0].myText.size = 12;
Value
Integer.
Default
20

type | NN 3 IE 4 DOM 1
| Read-only
Returns the type of form control element. The value is returned in all lowercase letters. It may be necessary to cycle through all form elements in search of specific types to do some processing on (e.g., emptying all form controls of type "text" while leaving other controls untouched).
Example
    if (document.forms[0].elements[3].type == "text") {
        // process text input type here
    }
Value
Any of the following constants (as a string): button | checkbox | file | hidden | image | password | radio | reset | select-multiple | select-one | submit | text | textarea.
Default
text

value | NN 2 IE 3 DOM 1
| Read/Write
Indicates the current value associated with the form control that is submitted with the name/value pair for the element. All values are strings, which means that scripts using text field values for some math operations (especially addition) have to convert the strings to numbers via the parseInt( ) or parseFloat( ) functions before performing the math. If you assign a number to a text field's value property, the browser automatically converts its data type to a string.
Example
    document.forms[0].myText.value = "franken";
Value
String.
Default
None.

createTextRange( ) | NN n/a IE 4(Win) DOM n/a
Creates a TextRange object from the content of the text object. See the TextRange object for details.
Parameters
None.
Returned Value
TextRange object.

handleEvent[ ] | NN |4| IE n/a DOM n/a
handleEvent(event) |
Instructs the object to accept and process the event whose specifications are passed as the parameter to the method. The object must have an event handler for the event type to process the event. Navigator 4 only.
Parameters

- A Navigator 4 event object.

Returned Value
None.

select( ) | NN 2 IE 3 DOM 1
Selects all the text displayed in the form element. You should invoke the focus( ) method on the element prior to the select( ) method. Moreover, to ease potential timing problems in IE for Windows, place the focus( ) and select( ) method statements in a separate function, and invoke that function through setTimeout( ), usually with a delay of 0 to 50 milliseconds. This lets the browser catch up with window refreshing tasks before selecting the contents.
Parameters
None.
Returned Value
None.