HTML | DOM Textarea required Property
The DOM Textarea required Property is used to set or return the Whether that the input element must be filled out before submitting the Form. This Property is used to reflect the HTML required attribute.
Syntax:
- It is used to Return the required property:
textareaObject.required
- It is used to Set the required property:
textareaObject.required = true|false
Property Values
- true: It specifies that the the textarea field must be filled out before submittted the form.
- false: It has a Default value. It specifies that the textarea field is not required part of the form.
Return Value: It returns a Boolean value which represents that the textarea field must be filled out or not before submitting the form.
Example-1: In HTML Program that illustrate how to return the required property.
<!DOCTYPE html> <html> <head> <title>DOM required textarea Property</title> <style> h1, h2 { color: green; font-style: italic; } body { text-align: center; } </style> </head> <body> <h1>GeeksForGeeks</h1> <h2>DOM required textarea Property</h2> <form action="/action_page.php"> <textarea id="GFG" rows="7" cols="50" name="comment" required> </textarea> <input type="submit"> </form> <br> <br> <button onclick="myGeeks()"> Try it </button> <p id="sudo"></p> <script> function myGeeks() { // Return Textarea property var x = document.getElementById("GFG").required; document.getElementById("sudo").innerHTML = x; } </script> </body> </html> |
Output:
Before Clicking On Tryit Button:

After Clicking On Tryit Button:

Example-2: In HTML Program that illustrate how to set the required property.
<!DOCTYPE html> <html> <head> <title>DOM required textarea Property</title> <style> h1, h2 { color: green; font-style: italic; } body { text-align: center; } </style> </head> <body> <h1>GeeksForGeeks</h1> <h2>DOM required textarea Property</h2> <form action="/action_page.php"> <textarea id="GFG" rows="7" cols="50" name="comment"> </textarea> <input type="submit"> </form> <br> <br> <button onclick="myGeeks()"> Try it </button> <p id="sudo"></p> <script> function myGeeks() { // Set Textarea property. var x = document.getElementById("GFG").required = true; document.getElementById("sudo").innerHTML = "Now the value of required attribute is set to True"; } </script> </body> </html> |
Output :
Before Clicking On Button:

After Clicking On Button:

Supported Browsers: The browser supported by Textarea required Property are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safari
Recommended Posts:
- HTML | <textarea> required Attribute
- HTML | DOM Textarea name Property
- HTML | DOM Textarea autofocus Property
- HTML | DOM Textarea cols Property
- HTML | DOM Textarea defaultValue property
- HTML | DOM Textarea rows Property
- HTML | DOM Textarea form Property
- HTML | DOM Textarea maxlength Property
- HTML | DOM Textarea wrap Property
- HTML | DOM Textarea readOnly Property
- HTML | DOM Textarea disabled Property
- HTML | DOM Textarea placeholder Property
- HTML | DOM Input URL required Property
- HTML | DOM Input Datetime required Property
- HTML | DOM Input Month required Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



