Javascript Reference - HTML DOM Textarea value Property








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.

Browser Support

value Yes Yes Yes Yes Yes

Syntax

Return the value property.

var v = textareaObject.value 

Set the value property.

textareaObject.value=text




Property Values

Value Description
text Specifies the text contents of the textarea

Return Value

A String type value representing the text content of the textarea.

Example

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:





Example 2

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: