Open In App

HTML DOM textarea minlength Property

Last Updated : 21 Jun, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The HTML DOM textarea minlength property is used to set or return the value of the minlength attribute of a textarea field. It specifies the minimum number of characters that have been allowed in the Element.

Syntax: 

  • It returns the minLength property. 
textareaObject.minLength
  • It is used to set the minLength property.  
textareaObject.minLength = number

Property Values: 

  • number: It specifies a minimum number of characters that are allowed in the textarea element.

Return Value: It returns a numeric value that represents the minimum number of characters that have been allowed in the Textarea field.

Example 1: HTML program to illustrate how to return the minlength property

HTML




<!DOCTYPE html>
<html>
 
<body>
    <h1 style="color:green;
               font-style:italic;">
        GeeksforGeeks
    </h1>
    <h2 style="color:green;
                   font-style:italic;">
        DOM Textarea minlength Property
    </h2>
    <textarea rows="4" cols="50"
              id="GFG" minlength="6">
        write here....
    </textarea>
    <br><br>
    <button onclick="myGeeks()">
        Submit
    </button>
    <p id="sudo"></p>
 
    <script>
        function myGeeks() {
 
            // Return minimum number of characters
            //allowed in the textarea field.
            let x =
                document.getElementById("GFG").minLength;
            document.getElementById("sudo").innerHTML =
                "There are only " + x + " minimum characters" +
                "are allowed in a Textarea Field.";;
        }
    </script>
 
</body>
 
</html>


Output: 

 

Examples: HTML program to illustrate how to sets the minlength property

HTML




<!DOCTYPE html>
<html>
 
<body>
    <h1 style="color:green;
               font-style:italic;">
        GeeksforGeeks
    </h1>
    <h2 style="color:green;
               font-style:italic;">
        DOM Textarea minlength Property
    </h2>
    <textarea rows="4" cols="50"
              id="GFG" minlength="6">
        write here....
    </textarea>
    <br><br>
    <button onclick="myGeeks()">
        Submit
    </button>
    <p id="sudo"></p>
 
    <script>
        function myGeeks() {
 
            // change minimum number of characters
           //allowed in the textarea field.
            let x =
                document.getElementById("GFG").minLength = "9";
            document.getElementById("sudo").innerHTML =
                "There are only " + x + " minimum characters" +
                "are allowed in a Textarea Field.";
        }
    </script>
 
</body>
 
</html>


Output: 

 



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads