Textarea defaultValue Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Textarea

Description

The defaultValue property sets or gets the default value of a text area, which is the value between the <textarea> and </textarea> tags.

Set the defaultValue property with the following Values

Value Description
text Sets the default value (contents) of the text area

Return Value

A String, representing the default value of the text area

The following code shows how to change the default value of a text area:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>
Address:<br>
<textarea id="myTextarea">
Main Street// w  w w  .j ava 2  s  .c om
New York</textarea>

<button type="button" onclick="myFunction()">Test</button>

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

</body>
</html>

Related Tutorials