Disable a 'enter/return' key function in a form I have a form in which a user needs to fill the fields. As only two fields are the required fields, so when user fills the required fields and press enter(windows)/return(mac) key the form gets submitted. I'm trying to disable the enter/return key function. So, for this I tried to inject a jQuery within the form.

my jQuery is as follows:

(function ($) {
Drupal.behaviors.YOURTHEMENAME = {
attach: function(context, settings) {
$("input").keypress(function (evt) {
var enterCode = evt.charCode || evt.keyCode;
if (enterCode  == 13) { return false;
}
});
  }
});
}
};
})(jQuery);


The jQuery part is familiar to me, but it doesn't work in the site. And the form responds to enter/return key press.

Is there any other way to disable enter/return key press. something like a module..
You need to use evt.preventDefault();

I wrote a blog post on making this work with drupal and ajaxified forms, which may let you see a slightly larger example including Drupal.behaviors.