Prevent submit for "ENTER" in particular text field

Prevent submit for "ENTER" in particular text field

Hey. I was wondering whether there was a good way to prevent a form from being submitted when the User hits the "Enter" key within a particular text field. I am just not sure whether the code below will work on all browsers and system - maybe a system identifies the Enter key as 0x0a or whatnot. And I'd prefer to have it all in a single event handler.

Right bow my code looks like this:
  1. // $("#searchField") is a text input element
  2. // and $("#f") is a form element around prior element

  3. var blockSubmit;


  4. $("#searchField").keydown(function(event){
  5.     if(event.which == 0x0d) {
  6.         blockSubmit = true;
  7.         sparteBoxChanged();
  8.     }
  9. });

  10. $("#f").submit(function(){
  11.     if(blockSubmit) {
  12.         blockSubmit = false;
  13.         return false;
  14.     } else {
  15.         return true;
  16.     }
  17. });