Latest web development tutorials

HTML DOM Input Text maxLength property

Input Text Object Reference Input Text Object

Examples

Text field allows for maximum input number of characters:

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

x The output is:

30

try it"


Definition and Usage

maxLength property sets or returns maxlength attribute values ​​in the text field.

maxLength attribute specifies the maximum input text field allows the number of characters.

Tip: If you want to set or returns the width of the text field, use the size property.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the disabled attribute.


grammar

Back maxLength attributes:

textObject .maxLength

Setting maxLength properties:

textObject .maxLength = number

Property Value

value description
number Text field specifies the maximum number of characters allowed to enter

Technical details

return value: Number number that represents the maximum text fields can be entered character


More examples

Examples

Set the text field to allow the maximum number of characters entered:

document.getElementById ( "myText") maxLength = "4".;

try it"

Examples

Automatically jump to the character of the text input field reaches the maximum number of characters in a text field next to continue to enter:

if (y.length == x.maxLength) {
var next = x.tabIndex;
if (next <document.getElementById ( "myForm"). length) {
document.getElementById ( "myForm") elements [next] .focus ().;
}
}

try it"


Related Pages

HTML Reference Manual: HTML <the INPUT> MAXLENGTH property


Input Text Object Reference Input Text Object