Reputation: 116353
I have an <input type="text" />
element. At some point, I don't want it to accept text anymore. For some reason, changing the type
to type="button"
for example is not allowed.
How can I make my <input>
element not accept text anymore?
Upvotes: 2
Views: 8172
Reputation: 139
With JavaScript, you can do document.getElementById("textbox").disabled = "disabled";
, which will make it read only.
Upvotes: 0
Reputation: 64216
Just disable the control with:
<input type="text" disabled="disabled" />
But be warned, it is still possible for a hacker to manipulate submitted form data. You should ensure that appropriate server-side validation is applied.
If using jQuery you can do the following:
HTML:
<input id="my-text-box" type="text" />
JS - jQuery 1.5-:
$('#my-text-box').attr('disabled', 'disabled');
JS - jQuery 1.6+:
$('#my-text-box').prop('disabled', true);
Upvotes: 1