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 |
A String, representing the name of the text area
The following code shows how to get the name of a text area:
<!DOCTYPE html> <html> <body> <textarea id="myTextarea" name="comment"> Some text in a text area....</textarea> <button onclick="display()">Display name</button> <button onclick="change()">Change name</button> <script> 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); } </script> </body> </html>