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.
document.getElementById('foo').disabled = true;
or
document.getElementById('foo').readOnly = true;
Note that readOnly
should be in camelCase to work correctly in Firefox (magic).
Demo: https://jsfiddle.net/L96svw3c/ -- somewhat explains the difference between disabled
and readOnly
.