Open In App

HTML | DOM Textarea name Property

Last Updated : 21 Jul, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

The DOM Textarea name Property is used to set or return the value of the name attribute of a textarea field. 

Syntax:

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

Property Values:

  • text: It specifies the name of the text area.

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

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

html




<!DOCTYPE html>
<html>
 
<head>
    <title>
      DOM Textarea name Property
  </title>
    <style>
        body {
            text-align: center;
        }
         
        h1,
        h2 {
            text-align: center;
        }
    </style>
</head>
 
<body>
    <h1 style="color: green;">
            GeeksforGeeks
        </h1>
 
    <h2>
            DOM Textarea name Property
        </h2>
 
    <textarea id="GFG"
              name="GFG_text">
        A computer science 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").name = "GFG_text2";
           
            document.getElementById("sudo").innerHTML =
                "The name is changed to " + x;
        }
    </script>
</body>
 
</html>


Output: 

Before Clicking On Button:

  

After Clicking On Button:

 

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

html




<!DOCTYPE html>
<html>
 
<head>
    <title>
      DOM Textarea name Property
  </title>
    <style>
        body {
            text-align: center;
        }
         
        h1,
        h2 {
            text-align: center;
        }
    </style>
</head>
 
<body>
    <h1 style="color: green;">
            GeeksforGeeks
        </h1>
 
    <h2>
            DOM Textarea name Property
        </h2>
 
    <textarea id="GFG" name="GFG_text">
        A computer science 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").name;
            document.getElementById(
              "sudo").innerHTML = x;
        }
    </script>
</body>
 
</html>


Output:

Before Clicking On Button:

  

After Clicking On Button:

  

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

  • Google Chrome 1 and above
  • Edge 12 and above
  • Internet Explorer 6 and above
  • Firefox 1 and above
  • Opera 12.1 and above
  • Safari 4 and above


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

Similar Reads