Skip to content
Related Articles

Related Articles

Improve Article

HTML | DOM Textarea defaultValue property

  • Difficulty Level : Basic
  • Last Updated : 22 Apr, 2019

The DOM Textarea defaultValue Property is used to set or return the default value of the textarea field.

Syntax:

  • It is used to return the defaultValue property.
    textareaObject.defaultValue
  • It is used to set the defaultValue property:
    textareaObject.defaultValue = text/value 

Property Values:

  • text: It specifies the default value of the text area.

Return Value: It returns the default value of the text area in the form of the string.

Example-1: HTML program to illustrate set the DOM Textarea defaultValue Property.






<!DOCTYPE html>
<html>
  
<head>
    <title>
      DOM Textarea defaultValue Property
  </title>
    <style>
        body {
            text-align: center;
        }
          
        h1,
        h2 {
            text-align: center;
        }
    </style>
</head>
  
<body>
    <h1 style="color: green;"
            GeeksforGeeks 
    </h1>
  
    <h2
        DOM Textarea defaultValue Property 
    </h2>
  
    <textarea id="GFG" 
              name="GFG_text">
        Portal for geeks.
    </textarea>
  
    <br>
    <br>
    <button type="button"
            onclick="myGeeks()">
      Submit
  </button>
    <p id="sudo"> </p>
    <script>
        function myGeeks() {
            document.getElementById("GFG").defaultValue =
                "A computer science portal for geeks";
  
        }
    </script>
</body>
  
</html>

Output :

Before Clicking On Button:

After Clicking On Button:

Example-2: HTML program to illustrate return the DOM Textarea defaultValue Property.




<!DOCTYPE html>
<html>
  
<head>
    <title>
      DOM Textarea defaultValue Property
  </title>
    <style>
        body {
            text-align: center;
        }
          
        h1,
        h2 {
            text-align: center;
        }
    </style>
</head>
  
<body>
    <h1 style="color: green;"
            GeeksforGeeks 
    </h1>
  
    <h2
        DOM Textarea defaultValue Property 
    </h2>
  
    <textarea id="GFG"
              name="GFG_text">
        Portal for geeks.
    </textarea>
  
    <br>
    <br>
    <button type="button" 
            onclick="myGeeks()">
      Submit
  </button>
    <p id="sudo"> </p>
    <script>
        function myGeeks() {
            var x = 
                document.getElementById("GFG").defaultValue;
            
            document.getElementById("sudo").innerHTML =
                "Default value is " + x;
  
        }
    </script>
</body>
  
</html>

Output
Before Clicking On Button:

After Clicking On Button:

Supported Browsers: The browser supported by Textarea defaultValue Property are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari

Attention reader! Don’t stop learning now. Get hold of all the important Comcompetitivepetitve Programming concepts with the Web Design for Beginners | HTML  course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :