views:

72

answers:

3

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?

A: 

You could:

$('#rush_needed_by_english').attr('disabled', 'disabled');
MyGGaN
No, that would make the field look disabled also and I am trying to avoid that. I just dont want them to be able to type.
zeckdude
+1  A: 
$('#rush_needed_by_english').keydown(function() {
  //code to not allow any changes to be made to input field
  return false;
});
PetersenDidIt
Perfect! Thank you!
zeckdude
Does this cover paste events? What if I click in the box, and type ctrl-V ?
Cheeso
+1  A: 
$('#rush_needed_by_english').attr('readonly', 'readonly');
Cory Larson