Textarea name Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Textarea


The name property sets or gets the name attribute of a text area.

Set the name property with the following Values

Value Description
text Sets the name of the text area

Return Value

A String, representing the name of the text area

The following code shows how to get the name of a text area:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<textarea id="myTextarea" name="comment">
Some text in a text area....</textarea>

<button onclick="display()">Display name</button>
<button onclick="change()">Change name</button>

function display() {
    var x = document.getElementById("myTextarea").name;
    console.log("The name of the text area is: " + x);

function change() {//from   ww  w  .  j a v a  2s  .  c om
    var x = document.getElementById("myTextarea").name = "newTxtName";
    console.log("The name was changed to: " + x);


Related Tutorials