input type="text" Element


 

Module

The input type="text" element is an inline element declared by the XHTML 1.1 Forms Module

Elements in the Forms Module are:
form | label | textarea | select | optgroup | option | button | fieldset | legend |
input type="button" | input type="checkbox" | input type="file" | input type="hidden" | input type="image" | input type="password" | input type="radio" | input type="reset" | input type="submit" | input type="text"

Description

The input type="text" element is used within a form to provide a single-line text box in which the user may enter a short length of text. The width of the text box may be specified using the size attribute.

The maxlength attribute may be used to specify the maximum number of characters which the user is allowed to enter. The user agent should prevent the user from entering more characters than this maximum number. Note, however, that processing code should not assume that it will never receive a value longer than this: quite apart from anything else, it is far from difficult to submit arbitrary input data to your processor without using a conventional browser.

The content of the value attribute (if present) is placed in the text box when the form is first rendered. The user may then edit the text (provided the element is not disabled or readonly) and the final edited text is sent to the processing URI as the value in a name=value pair.

Here is an example using the input type="text" element:

<label for="uname">Username:</label>
<input type="text" id="uname" name="uname" size="15" maxlength="12" value="Your username" />

This renders as:

See also the textarea element for the input of long blocks of text and the input type="password" element for the input of short text which should be visually hidden from any onlookers (as the name suggests, this is intended for password entry).

#REQUIRED Attributes

There are no #REQUIRED attributes on the input type="text" element.


Specific Attributes

Specific attributes of the input type="text" element are listed below:

From the Forms Module - the Element's own Module

The type attribute is not #REQUIRED on the input element and so, because its default value is "text", it does not need to be present on input type="text".

accesskey [ type Character ]
Key to be pressed which allows focus to be directed immediately to this input element to allow text input
disabled [ type Boolean ]
If this attribute is present, the text input field is initially disabled - no data is sent to the processing URI for disabled elements when the form is submitted. The user cannot interact with a disabled control.
maxlength [ type Number ]
The maximum number of characters accepted by the text input control
name [ type CDATA ]
This is the name sent to the processing URI for the text input field when the form is submitted (if the name attribute is not present, the value of the text field will not be sent). The value sent (in a name=value pair) is the text in the input field at the time of submission.

Note: Although technically optional, a note in the *Forms Module DTD says that the name attribute is required on all input elements except "submit" and "reset"

readonly [ type Boolean ]
If this attribute is present, the text input field may not (initially) be modified by the user. Data may still be sent to the processing URI for readonly fields.
size [ type Number ]
Initial display width of the text input field in characters (based on an average character width)
tabindex [ type Number ]
An integer between 0 and 32767 specifying the position of the text input field in the tabbing order of the document
value [ type CDATA ]
The initial value to be entered in the text input field when the form is first rendered - the field is returned to this value if the form is reset

From the Intrinsic Events Module

onblur [ type Script ]
Script to be executed when the element loses focus
onchange [ type Script ]
Script to be executed if the text within the text input field has been changed (it is triggered only when the element loses focus and its content has changed since last gaining focus)
onfocus [ type Script ]
Script to be executed when the element receives focus
onselect [ type Script ]
Script to be executed when some text within the text input field is highlighted

Common Attributes

Common attributes of the input type="text" element are listed below:

From the Core Attribute Collection

class [ type NMTOKENS ]
One or more space separated classes
id [ type ID ]
A unique identifier for the element
style [ type CDATA ], from the Style Attribute Module (deprecated)
Element-specific styles
title [ type Text ]
Descriptive title for the element (in some user agents this may appear as a "tooltip" when the mouse hovers over the element)
xmlns [ type URI - #FIXED 'http://www.w3.org/1999/xhtml' ]
XML namespace

From the I18N Attribute Collection

dir [ type Enumeration (ltr | rtl) ], from the Bi-directional Text Module
Left-to-right or right-to-left directionality
xml:lang [ type LanguageCode ]
A language code for the element

From the Events Attribute Collection

All attributes in the Events Attribute Collection are supported:
onclick, ondblclick, onmousedown, onmouseup, onmouseover, onmousemove, onmouseout, onkeypress, onkeydown, onkeyup


Content Model

The Content Model for the input type="text" element is:

EMPTY

See Content Model & Nesting for information about Content Model syntax and Nesting Groups.

Valid children of input type="text"

This element is empty and may have no children.

Valid parents of input type="text"


Page Footer & Copyright

Copyright © Sally Maughan 2005-2009 (Page last updated on 01 Oct 2009)

*Valid XHTML 1.1 - hosted by *Openstrike

Content based on the W3C Working Draft: *XHTML 1.1 and Recommendation: *XHTML Modularisation 1.1.

W3C, XHTML, XML, HTML, CSS and MathML are *Trademarks of the W3C (*MIT, *ERCIM, *Keio) with which the site's author has no connection.


Up, Next & Previous Links

Your Location

Home > XHTML 1.1 Home > XHTML 1.1 Indexes > Element Index (XHTML 1.1) > input Elements > input type="text"