The value of a textarea is the text between the <textarea> and </textarea> tags.
The value
property sets or gets the contents of a textarea.
value |
Yes | Yes | Yes | Yes | Yes |
Return the value property.
var v = textareaObject.value
Set the value property.
textareaObject.value=text
Value | Description |
---|---|
text | Specifies the text contents of the textarea |
A String type value representing the text content of the textarea.
The following code shows how to change the contents of a textarea.
<!DOCTYPE html>
<html>
<body>
Address:<br>
<textarea id="myTextarea">
this is a test<!--from ww w . j a va2 s. co m-->
</textarea>
<button type="button" onclick="myFunction()">test</button>
<script>
function myFunction() {
document.getElementById("myTextarea").value = "new value";
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to get the contents of a textarea.
<!DOCTYPE html>
<html>
<body>
<!-- ww w. j a va 2 s . c o m-->
Address:<br>
<textarea id="myTextarea">
this is a test
</textarea>
<button type="button" onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myTextarea").value;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: