Input Search maxLengthProperty
Example
Get the maximum number of characters allowed in the search field:
var x = document.getElementById("mySearch").maxLength;
xThe result is:30
Try it Yourself »
Definition and Usage
The maxLength property is used to set or return the value of the maxlength attribute of the search field.
The maxLength property describes the maximum number of characters allowed in the search field.
The default value is 524288.
Tip:If you need to set or return the length (number of characters) of the search field, use thesizeproperty.
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the maxLength property.
Syntax
Return the maxLength property:
searchObject.maxLength
Set the maxLength property:
searchObject.maxLength=number
Property Value
| Value | Description |
|---|---|
| number | Describes the maximum number of characters allowed in the search field, default is 524288 |
Technical Details
| Return Value: | A number representing the maximum number of characters allowed in the search field. |
|---|
More Examples
Example
Change the maximum number of characters allowed in the search field:
document.getElementById("mySearch").maxLength = "8";
Try it Yourself »
Related Pages
HTML Reference:HTML <input> maxlength Attribute
Input Search Object Other Extensions