Set Input to Read-Only: HTML & JS
You can set the input to read-only by using one of the following methods:
- Use HTML attribute: set the readonly attribute of the input element to “readonly”. For example:
<input type="text" readonly>
- Use JavaScript to set the readonly attribute of the input element to true. For example:
document.getElementById("myInput").readOnly = true;
The “myInput” is the ID of the input element, and you can modify it according to your actual situation.
You can make an input read-only by using either HTML attributes or JavaScript.