Javascript DOM HTML Textarea readOnly Property

Introduction

Set a text area to be read-only:

document.getElementById("myTextarea").readOnly = true;

Click the button to set the text area to read-only.

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() {//w w w.j  a va 2s  .c o m
  document.getElementById("myTextarea").readOnly = "true";
}
</script>

</body>
</html>

The readOnly property sets or gets whether the contents of a text area should be read-only.

This property mirrors the HTML readonly attribute.

Value Description
true The text area is read-only
falseDefault. The text area is changeable

The readOnly property returns true if the text area is read-only, otherwise it returns false.




PreviousNext

Related