You are here: Reference > JavaScript > client-side > HTML DOM > properties > maxLength (input, isindex)
maxLength property (input, isindex)
Sets or retrieves the maximum number of characters allowed in a text box.
If the maximum number of characters is reached, the user cannot add more characters to the contents of the input element.
Syntax:
You can find the related objects in the Supported by objects section below.
This property is read/write.
HTML page for this property: maxLength |
Possible values:
Integer that sets or retrieves the maximum length of text, in characters. Zero and negative integers mean that no characters can be entered into the input box.
Default: this property has no default value.
Example HTML code 1:
This example illustrates the use of the maxLength attribute:
|
||||
<input type="text" maxlength="4" size="20" /> |
||||
|
||||
Did you find this example helpful?
|
Example HTML code 2:
This example illustrates the use of the maxLength property:
|
||||
<head> <script type="text/javascript"> function SetMaxLength () { var input = document.getElementById ("myInput"); input.maxLength = 10; } </script> </head> <body> Please enter characters into the input field <input id="myInput" type="text" maxlength="4" size="20" /> <button onclick="SetMaxLength ();">Allow 8 chars!</button> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
HTML elements:
Related pages:
External links:
User Contributed Comments