The name
property sets or gets the name attribute of a textarea.
The name value is used to reference form data after a form is submitted.
We can use the name
attribute value to
reference elements in a JavaScript.
name |
Yes | Yes | Yes | Yes | Yes |
Return the name property.
var v = textareaObject.name
Set the name property.
textareaObject.name=text
Value | Description |
---|---|
text | Set the name of the textarea |
A String type value representing the name of the textarea.
The following code shows how to get the name of a textarea.
<!DOCTYPE html>
<html>
<body>
<!--from www . j a va 2 s . c o m-->
<textarea id="myTextarea" name="comment">
Some text in a textarea....</textarea>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myTextarea").name;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to change the name of a textarea.
<!DOCTYPE html>
<html>
<body>
<!-- ww w . j av a2 s. co m-->
<textarea id="myTextarea" name="comment">
Some text in a textarea....</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 is: " + x);
}
function change() {
var x = document.getElementById("myTextarea").name = "newTxtName";
console.log("The name was changed to: " + x);
}
</script>
</body>
</html>
The code above is rendered as follows: