The defaultValue
property sets or gets the default value of a textarea.
defaultValue |
Yes | Yes | Yes | Yes | Yes |
Return the defaultValue property.
var v = textareaObject.defaultValue
Set the defaultValue property.
textareaObject.defaultValue=text
Value | Description |
---|---|
text | Set the default value of the textarea |
A String type value representing the default value of the textarea.
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:
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: