I want to disable writing in an input field of type text using JavaScript, if possible.
The input field is populated from a database; that is why I don’t want the user to modify its value.
I want to disable writing in an input field of type text using JavaScript,
Share
If you know this when the page is rendered, which it sounds like you do because the database has a value, it’s better to disable it when rendered instead of JavaScript. To do that, just add the
readonlyattribute (ordisabled, if you want to remove it from the form submission as well) to the<input>, like this: