The Wayback Machine - https://web.archive.org/web/20240921171659/https://www.geeksforgeeks.org/html-dom-input-text-maxlength-property/
Open In App

HTML | DOM Input Text maxLength Property

Last Updated : 13 Oct, 2022
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

The DOM Input Text maxLength Property in HTML DOM is used to set or return the value of maxlength attribute of a Text Input Field. It specifies the maximum number of characters that have been allowed in the text field. The default value of Input Text  maxLength property is 524288. 

Syntax:

  • It returns the Input Text maxLength property.
textObject.maxLength
  • It is used to set the Input text maxLength property.
textObject.maxLength = number

Property Values: It contains a single value number which is used to specify the maximum number of characters that are allowed in the text maxlength Field. 

Return Value: It returns a numeric value which represents the maximum number of character that has been allowed in the text maxlength field. 

Example 1: This example illustrates how to return the Input text maxLength property. 

HTML




<!DOCTYPE html>
<html>
<head>
    <title>
        HTML DOM Input Text maxLength Property
    </title>
</head>
<body style="text-align:center;">
    <h1>GeeksForGeeks</h1>
    <h2>DOM Input Text maxLength Property</h2>
    <form id="myGeeks">
        <input type="text" id="text_id"
        name="geeks" pattern="[A-Za-z]{3}">
    </form>
    <br>
    <button onclick="myGeeks()">Click Here!</button>
    <p id="GFG" style="font-size:20px;"></p>
     
    <!-- Script to set the maxLength Property-->
    <script>
        function myGeeks() {
            var txt = document.getElementById("text_id").maxLength;
            document.getElementById("GFG").innerHTML = txt;
        }
    </script>
</body>
</html>


Output: 

Before clicking on the button:

  

After clicking on the button:

  

Example-2: This Example illustrates how to set the property. 

HTML




<!DOCTYPE html>
<html>
<head>
    <title>
        HTML DOM Input Text maxLength Property
    </title>
</head>
<body style="text-align:center;">
    <h1>GeeksForGeeks</h1>
    <h2>DOM Input Text maxLength Property</h2>
    <form id="myGeeks">
        <input type="text" id="text_id"
            name="geeks" maxlength="60">
    </form>
    <br>
    <button onclick="myGeeks()">Click Here!</button>
    <p id="GFG" style="font-size:20px;"></p>
     
    <!-- script to set the maxLength Property-->
    <script>
        function myGeeks() {
            var txt = document.getElementById("text_id").maxLength;
            document.getElementById("GFG").innerHTML =
        "The value of the maxLength attribute was changed to " + txt;
        }
    </script>
</body>
</html>


Output: 

Before clicking on the button:

  

After clicking on the button:

  

Supported Browsers: The browser supported by DOM input Text maxLength Property are listed below:

  • Google Chrome 1+
  • Edge 12+
  • Firefox 1+
  • Opera
  • Safari 1+


Similar Reads

HTML | DOM Input Email maxLength Property
The Input Email maxLength property in HTML DOM is used to set or return the value of maxlength attribute of a Email Input Field. It specifies the maximum number of characters that have been allowed in the email field. The default value of Input Email maxLength property is 524288. Syntax: It returns the Input Email maxLength property. emailObject.ma
2 min read
HTML | DOM Input Password maxLength Property
The DOM Input Password maxLength Property is used to set or return the value of a maxLength attribute of a password field. It specifies the maximum number of characters that have been allowed in the element. Syntax: It is used to return the maxLength property.passwordObject.maxLengthIt is used to set the maxLength property.passwordObject.maxLength
2 min read
HTML | DOM Input Search maxLength Property
The DOM Input Search maxLength Property in HTML DOM is used to set or return the value of maxlength attribute of a search Input Field. It specifies the maximum number of characters that have been allowed in the search field. The default value of Input search maxLength property is 524288. Syntax: It returns the Input search maxLength property.search
2 min read
HTML | DOM Input URL maxLength Property
The DOM Input URL maxLength Property in HTML DOM is used to set or return the value of maxlength attribute of a URL Input Field. It specifies the maximum number of characters that have been allowed in the URL field. The default value of Input URL maxLength property is 524288. Syntax: It returns the Input url maxLength property. urlObject.maxLength
2 min read
HTML | DOM Textarea maxlength Property
The DOM Textarea maxlength Property is used to set or return the value of the maxlength attribute of a textarea field. It specifies the maximum number of characters that have been allowed in the Element. Syntax: It is used to return the maxLength property: textareaObject.maxLength It is used to set the maxLength property: textareaObject.maxLength =
2 min read
HTML input maxlength Attribute
The &lt;input&gt; maxlength attribute is used to specify the maximum number of characters entered into the &lt;input&gt; element. The input has no maximum length if no value is specified or if an invalid value is specified. The length is measured in UTF-16 code units, which is equivalent to the number of characters. Syntax&lt;input maxlength="numbe
2 min read
jQWidgets jqxTextArea maxLength Property
jQWidgets is a JavaScript framework for making web-based applications for PC and mobile devices. It is a very powerful, optimized, platform-independent, and widely supported framework The jqxTextArea represents a jQuery Textarea widget that is used to insert text content inside the textbox. The maxLength property is used to set or return the maximu
2 min read
jQWidgets jqxInput maxLength Property
jQWidgets is a JavaScript framework for making web-based applications for PC and mobile devices. It is a very powerful, optimized, platform-independent, and widely supported framework. The jqxInput is used to represent a jQuery input widget that contains auto-complete features The maxLength property is used to set or return the maximum character le
2 min read
jQWidgets jqxPasswordInput maxLength Property
jQWidgets is a JavaScript framework for making web-based applications for PC and mobile devices. It is a very powerful, optimized, platform-independent, and widely supported framework. The jqxPasswordInput is a jQuery widget that enables the input field passwords with nice visual feedback about the password's strength. The maxLength property is use
2 min read
HTML &lt;textarea&gt; maxlength attribute
The HTML &lt;textarea&gt; maxlength attribute is used to specify the maximum number of characters entered into the textarea element. Syntax: &lt;textarea maxlength ="number"&gt;Attribute Value: Attribute Value Description number It contains a single value number which allows the maximum number of characters in the Textarea element. Its default valu
2 min read
HTML maxlength Attribute
It specifies the maximum number of characters that have been allowed in the Element. It can be used on the following Elements:  &lt;input&gt;&lt;textarea&gt;Attribute Values: It contains a single value number that allows the maximum number of characters in the &lt;input&gt; element. Its default value is 524288. Examples: In this example, we center
2 min read
HTML | DOM Input Text value Property
The Input Text value property in HTML DOM is used to set or return the value of a value attribute of the input field. The value attribute specifies the initial value of the input Text Field. It contains the default value or the user types. Syntax: It returns the Input Text value property. textObject.valueIt is used to set the Input Text value prope
2 min read
HTML | DOM Input Text size Property
The Input Text size Property in HTML DOM is used to set or return the value of the size attribute of an Input Text Field. The size attribute is used to define the width of a text field. Its default value is 20. Syntax: It returns the Input Text size property.textObject.sizeIt is used to set the Input Text size property.textObject.size = number Prop
2 min read
HTML | DOM Input Text placeholder Property
The Input Text Placeholder property in HTML DOM is used to set or return the value of the placeholder attribute of a text field. The placeholder attribute specifies the short hint that describes the expected value of an input field. The short hint is displayed in the field before the user enters a value. Syntax: It returns the Input Text Placeholde
2 min read
HTML | DOM Input Text readOnly Property
The Input Text readOnly property in HTML DOM is used to set or return whether a text field should be read-only or not. It means that a user can not modify or changes the content already present in a particular element (However, a user can tab to it, highlight it, and copy the text from it) whereas a JavaScript can be used to change the read-only va
2 min read
HTML | DOM Input Text pattern Property
The Input Text pattern Property in HTML DOM is used to set or return the pattern attribute of an text field. It is used to specify the regular expression on which the input elements value is checked. Use the global title attribute to describe the pattern for helping the user. Syntax: It returns the Input Text pattern property.textObject.patternIt i
2 min read
HTML | DOM Input Text required Property
The Input Text required Property in HTML DOM is used to set or return whether Input Text Field should be filled or not when submitting the form. This property is used to reflect the HTML required attribute. Syntax: It returns the Input text required property.textObject.requiredIt is used to set the Input text required property.textObject.required =
2 min read
HTML DOM Input Text defaultValue Property
The Input Text defaultValue Property in HTML DOM is used to set or return the default value of the Text Field. This property is used to reflect the HTML value attribute. The main difference between the default value and value is that the default value indicate the default value and the value contains the current value after making some changes. Thi
2 min read
HTML | DOM Input Text name Property
The DOM Input Text name Property in HTML DOM is used to set or return the value of name attribute of a Textfield. The name attribute is required for each input field. If the name attribute is not specified in an input field then the data of that field would not be sent at all. Syntax: It returns the Input Text name property.textObject.nameIt is use
2 min read
HTML | DOM Input Text form Property
The DOM Input Text form Property in HTML DOM is used to return the reference of form containing the input Text field. It is a read-only property that returns the form object on success. Syntax: textObject.form Return Values: It returns a string value which specify the reference of the form containing the Input Text field. Example: This example illu
1 min read
HTML | DOM Input Text disabled Property
The DOM Input Text disabled Property is used to set or return the whether the Input Text Field must be disabled or not. A disabled Text Field is un-clickable and unusable. It is a boolean attribute and used to reflect the HTML Disabled attribute. It is usually rendered in grey color by default in all the Browsers.Syntax: It returns the disabled pro
2 min read
HTML | DOM Input Text autofocus Property
The DOM Input Text autofocus Property in HTML DOM is used to set or return whether the Input Text Field should get focus when the page loads. It reflects the HTML autofocus attribute. Syntax: It returns the autofocus property.textObject.autofocusIt is used to set the autofocus property.textObject.autofocus = "true|false" Property Values: true: It s
2 min read
HTML | DOM Input Text autocomplete Property
The DOM Input Text autocomplete Property in HTML DOM is used to set or return the value of the autocomplete attribute of an Input Text field. The autocomplete attribute is used to specify whether the autocomplete attribute has “on” or “off” value. When the autocomplete attribute is set to on the browser will automatically complete the values base o
2 min read
HTML DOM Input Text minLength Property
The HTML DOM Input Text minLength property in HTML DOM is used to set or return the value of the minlength attribute of a Text Input Field. It specifies the minimum number of characters that have been allowed in the text field. The default value of the Input Email minLength property is 524288. Syntax: It returns the Input Text minLength property.te
2 min read
HTML DOM Input Text list Property
The input Text list property in HTML DOM is used to return a reference to the datalist element that contains an input text field. Syntax: textObject.list.id Return Value: It returns a string value that represents the value of the id attribute of the datalist element. Example: Below HTML code used to return the input text list property. C/C++ Code
1 min read
HTML DOM Input Text type Property
The Input Text type Property in HTML DOM is used to return the type of form element of the text field. It always returns the text for an Input text field. Syntax:  textObject.typeReturn Value: It returns a string value that represents the type of form element the input text field is. Below program illustrates the text type property in HTML DOM: Exa
1 min read
AngularJS ng-maxlength Directive
The ng-maxlength Directive in AngularJS is used to set the maximum length for an input field i.e it adds the restriction for an input field. It is different from maxlength attribute in HTML because the former prevents users from exceeding the limit whereas the later doesn't do that. It will make the form invalid if the input limit exceeds it. Synta
2 min read
How to select all text in HTML text input when clicked using JavaScript?
This example shows how to select entire input in a single click using javaScript. Syntax: &lt;input onClick="this.select();" &gt; or document.getElementById("ID").select(); Example-1: Using "this.select()". &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt; Select all text in HTML text input when clicked &lt;/title&gt; &lt;/head&gt; &lt;
1 min read
HTML | DOM Input Text Object
The Input Text Object in HTML DOM is used to represent the HTML &lt;input&gt; element with type="text" attribute. The &lt;input&gt; element with type="text" can be accessed by using getElementById() method. Syntax: It is used to access input text object. document.getElementById("id");It is used to create input element. document.createElement("input
3 min read
HTML DOM Input Text select() Method
The DOM Input select() method selects all the text content of a textarea or an input element that contains the text field. Syntax: element.select(); Parameters: This method does not accept any parameters. Example: This example selects the content of the input text field. C/C++ Code &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt; HTML
1 min read
Article Tags :