The disabled
property disables or enables
a text field.
disabled |
Yes | Yes | Yes | Yes | Yes |
Return the disabled property.
var v = textObject.disabled
Set the disabled property.
textObject.disabled=true|false
Value | Description |
---|---|
true|false | Set whether a text field should be disabled.
|
A Boolean type value, true if the text field is disabled, otherwise false
The following code shows how to check if a text field is disabled.
<!DOCTYPE html>
<html>
<body>
<!--from ww w. j a v a 2 s. c om-->
Name: <input type="text" id="myText">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myText").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 text field.
<!DOCTYPE html>
<html>
<body>
<!--from w ww .ja va 2s . c o m-->
First Name: <input type="text" id="myText" value="Mickey"><br>
<button onclick="disableTxt()">Disable Text field</button>
<button onclick="enableTxt()">Enable Text field</button>
<script>
function disableTxt() {
document.getElementById("myText").disabled = true;
}
function enableTxt() {
document.getElementById("myText").disabled = false;
}
</script>
</body>
</html>
The code above is rendered as follows: