Javascript Reference - HTML DOM Textarea disabled Property








The disabled property disables or enables a textarea.

Browser Support

disabled Yes Yes Yes Yes Yes

Syntax

Return the disabled property.

var v = textareaObject.disabled 

Set the disabled property.

textareaObject.disabled=true|false 

Property Values

Value Description
true|false Disable or enable a textarea.
  • true - The textarea is disabled
  • false - Default. The textarea is not disabled




Return Value

A Boolean type value, true if the textarea is disabled, otherwise false.

Example

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:





Example 2

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:

Example 3

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: