How to prevent user from typing in text field without disabling the field?
A non-Javascript alternative that can be easily overlooked: can you use the readonly
attribute instead of the disabled
attribute? It prevents editing the text in the input, but browsers style the input differently (less likely to "grey it out")
e.g. <input readonly type="text" ...>
if you don't want the field to look "disabled" or smth, just use this:
onkeydown="return false;"
it's basically the same that greengit and Derek said but a little shorter
$('input').keydown(function(e) {
e.preventDefault();
return false;
});