Textarea readOnly Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Textarea

Description

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

This property reflects the HTML readonly attribute.

Set the readOnly property with the following Values

Value Description
true|false Sets whether a text area should be read-only

Return Value

A Boolean, returns true if the text area is read-only, otherwise it returns false

The following code shows how to Set a text area to be read-only:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>
Address:<br>
<textarea id="myTextarea">
Main Street//from   www. j av  a  2 s  .  c o m
New York</textarea>

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

<script>
function myFunction() {
    document.getElementById("myTextarea").readOnly = "true";
}
</script>

</body>
</html>

Related Tutorials