The readOnly
property sets or gets
whether the textarea is read-only.
readOnly |
Yes | Yes | Yes | Yes | Yes |
Return the readOnly property.
var v = textareaObject.readOnly
Set the readOnly property.
textareaObject.readOnly=true|false
Value | Description |
---|---|
true|false | Set whether a textarea is read-only.
|
A Boolean type value, returns true if the textarea is read-only, otherwise false.
The following code shows how to set a textarea to be read-only.
<!DOCTYPE html>
<html>
<body>
<textarea id="myTextarea">
this is a test<!--from w ww . j a v a2 s. com-->
</textarea>
<button type="button" onclick="myFunction()">test</button>
<script>
function myFunction() {
document.getElementById("myTextarea").readOnly = "true";
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to check if a textarea is read-only or not.
<!DOCTYPE html>
<html>
<body>
<textarea id="myTextarea" readonly>
this is a test<!--from w ww.jav a 2 s .co m-->
</textarea>
<button type="button" onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myTextarea").readOnly;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: