I am using the jQuery datepicker on a text input field and I don't want to let the user change any of the text in the text input box with the keyboard.
Here's my code:
$('#rush_needed_by_english').keydown(function() {
//code to not allow any changes to be made to input field
});
How do I not allow keyboard typing in a text input field using jQuery?
The disabled attribute can be set to keep a user from using the <input> element until some other condition has been met (like selecting a checkbox, etc.). Then, a JavaScript could remove the disabled value, and make the <input> element usable.
To make a textarea and input type read only, use the attr() method .
You can use the below code to disable the editing of in KendoDatePicker. $("#datepicker"). attr("disabled","disabled"); In above code datepicker is the id of textbox control.
$('#rush_needed_by_english').keydown(function() {
//code to not allow any changes to be made to input field
return false;
});
You could simply make the field read-only with:
$('#rush_needed_by_english').attr('readonly', 'readonly');
If you're using jQuery 1.6+, you should use the prop()
method instead:
$('#rush_needed_by_english').prop('readOnly', true);
// careful, the property name string 'readOnly' is case sensitive!
Or ditch jQuery and use plain JavaScript:
document.getElementById('rush_needed_by_english').readOnly = true;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With