Sometimes, we want to disable a text input with JavaScript.
In this article, we’ll look at how to disable a text input with JavaScript.
How to disable a text input with JavaScript?
To disable a text input with JavaScript, we set its disabled
or readOnly
property to true
.
For instance, we write
document.getElementById("foo").disabled = true;
to select the input with getElementById
.
And then we set its disabled
property to true
.
We can also write
document.getElementById("foo").readOnly = true;
to disable the input.
Conclusion
To disable a text input with JavaScript, we set its disabled
or readOnly
property to true
.