Javascript DOM HTML Textarea defaultValue Property

Introduction

Change the default value of a text area:

document.getElementById("myTextarea").defaultValue = "Fifth Avenue, New York City";

Click the button to change the default value of the text area.

View in separate window

<!DOCTYPE html>
<html>
<body>

Address:<br>
<textarea id="myTextarea">
PO 1234, Main Street U.S.A.
New York</textarea>
<button type="button" onclick="myFunction()">Test</button>

<script>
function myFunction() {//from  w  w w.  j a v a 2  s.co  m
  document.getElementById("myTextarea").defaultValue = "Fifth Avenue, New York City";
}
</script>

</body>
</html>

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

The default value of a text area is the text between the <textarea> and </textarea> tags.

The defaultValue property accepts and returns a String type value.




PreviousNext

Related