The disabled
property disables or enables a textarea.
disabled |
Yes | Yes | Yes | Yes | Yes |
Return the disabled property.
var v = textareaObject.disabled
Set the disabled property.
textareaObject.disabled=true|false
Value | Description |
---|---|
true|false | Disable or enable a textarea.
|
A Boolean type value, true if the textarea is disabled, otherwise false.
The following code shows how to disable a textarea.
<!DOCTYPE html>
<html>
<body>
<textarea id="myTextarea">
this is a test<!--from w w w. j av a 2 s.com-->
</textarea>
<button onclick="myFunction()">Disable Textarea</button>
<script>
function myFunction() {
document.getElementById("myTextarea").disabled = true;
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to check if a textarea is disabled.
<!DOCTYPE html>
<html>
<body>
<textarea id="myTextarea">
</textarea>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!-- ww w . ja va 2 s . c o m-->
var x = document.getElementById("myTextarea").disabled;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to disable and enable a textarea.
<!DOCTYPE html>
<html>
<body>
<textarea id="myTextarea">
</textarea>
<button onclick="disableTxt()">Disable textarea</button>
<button onclick="enableTxt()">Enable textarea</button>
<!-- w w w.ja va2 s . c o m-->
<script>
function disableTxt() {
document.getElementById("myTextarea").disabled = true;
}
function enableTxt() {
document.getElementById("myTextarea").disabled = false;
}
</script>
</body>
</html>
The code above is rendered as follows: