Javascript Reference - HTML DOM Textarea defaultValue Property








The defaultValue property sets or gets the default value of a textarea.

Browser Support

defaultValue Yes Yes Yes Yes Yes

Syntax

Return the defaultValue property.

var v = textareaObject.defaultValue 

Set the defaultValue property.

textareaObject.defaultValue=text

Property Values

Value Description
text Set the default value of the textarea




Return Value

A String type value representing the default value of the textarea.

Example

The following code shows how to change the default value of a textarea.


<!DOCTYPE html>
<html>
<body>
<!--from www.ja va2  s .  c o  m-->
<textarea id="myTextarea">
</textarea>
<button type="button" onclick="myFunction()">test</button>

<script>
function myFunction() {
    document.getElementById("myTextarea").defaultValue = "new value";
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to get the default value of a textarea.


<!DOCTYPE html>
<html>
<body>
<textarea id="myTextarea">
</textarea>
<button type="button" onclick="myFunction()">test</button>
<!--  w  w  w. j  a v a 2s  . com-->
<p id="demo"></p>

<script>
function myFunction() {
    var x = document.getElementById("myTextarea").defaultValue;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows: