AvailabilityJavaScript 1.0; enhanced in JavaScript 1.1 Inherits from/OverridesInherits from Input, HTMLElement Synopsisform.name form.elements[i] PropertiesText inherits properties from Input and HTMLElement and defines or overrides the following:
MethodsText inherits the methods of Input and HTMLElement. Event HandlersText inherits the event handlers of Input and HTMLElement and defines or overrides the following:
HTML SyntaxA Text element is created with a standard HTML <input> tag: <form> ... <input type="text" // Specifies that this is a Text element [ name="name" ] // A name you can use later to refer to this element // Specifies the name property [ value="default" ] // Default value transmitted when the form is submitted // Specifies the defaultValue property [ size="integer" ] // How many characters wide the element is [ maxlength="integer" ] // Maximum allowed number of input characters [ onchange="handler" ] // The onchange( ) event handler > ... </form> DescriptionThe Text element represents a text input field in a form. The size attribute specifies the width, in characters, of the input field as it appears on the screen, and the maxlength attribute specifies the maximum number of characters the user is allowed to enter. Besides these HTML attributes, value is the main property of interest for the Text element. You can read this property to obtain the user's input or set it to display arbitrary (unformatted) text in the input field. UsageUse the Password element instead of the Text element when the value you are asking the user to enter is sensitive information, such as a password that should not be displayed openly on the screen. Use a Textarea element to allow the user to enter multiple lines of text. When a form contains only one Text or Password element, the form is automatically submitted if the user strikes the Return key in that Text or Password element. In many forms, this is a useful shortcut. In some, however, it can be confusing if the user strikes Return and submits the form before entering input into other form elements, such as Checkboxes and Radio buttons. You can sometimes minimize this confusion by placing Text elements with their default submission action at the bottom of the form. See AlsoForm, Input, Password, Textarea; HTMLInputElement in the DOM reference section |