Input Text sizeProperty

Input Text 对象参考手册Input Text Object

Examples

Set the size of a text field (in characters):

document.getElementById("myText").size = "50";

Try it Yourself »


Definition and Usage

The size property sets or returns the value of the size attribute of a text field.

The size property sets or returns the size of a text field (in characters).

The default value is 20.

Tip:To set or return the number of characters allowed in a password field, use the maxLengthattribute.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

All major browsers support the size attribute


Syntax

Return the size property:

textObject.size

Set the size property:

textObject.size=number

Property Values

Value< Description
number Specifies the width of a text field, in characters. The default value is 20.

Technical Details

Return Value: A Number, representing the size of the text field, in characters


More Examples

Examples

Get the size of a text field:

var x = document.getElementById("myText").size;

xThe result is:

30

Try it Yourself »


Related Pages

HTML Reference Manual:HTML <input> size Attribute


Input Text 对象参考手册Input Text Object Other Extensions