title: I have problems with keydown event and autocomplete in Firefox on mac
body: <p>This is driving me nuts. Its a tough one to explain but I'll have a go.</p>
  
  <p>I have one input text field on the front page of my site. I have coded a keydown event observer which checks the keyCode and if its ENTER (or equiv), itll check the input value (email). If the email is valid and unique in the DB itll submit the form. Basic stuff, or so you would think.</p>
  
  <p>If I type my email address in the field and hit enter, it works fine in all browsers. However, if I type the first couple of letters, and then use the arrow keys to select the email from the history dropdown box (hope you know what I mean here), and then press enter the result is different. The value of the form field is being captured as just the couple of letters I typed, and therefore the validation is failing. It seems that when I press the enter key to "select" the email from the history dropdown, the browser is interrupting that as if I was typing.</p>
  
  <p>In Chrome and Safari it works as it should. As it should means that when you press enter to "select" the email from the history dropdown, all it does is puts that email address into the text box. Only on the second ENTER key press does it then trigger the event observer, and the email is validated.</p>
  
  <p>Hope somebody can shed some light on why this is happening... My gut feeling is its a browser thing and will be something I cant fix.</p>
  
  <p>Thanks
  Lee</p>
  
  <p>EDIT:
  To add clarification to my question let me add that Im using the "keydown" event to capture the moment when the enter key is pressed. I have tried the "keyup" event and this solved my problem above, but then I cant seem to stop the form submitting by itself. The "keyup" event triggers AFTER the default behaviour, therefore its not the right choice for this.</p>
  
  <p><strong>FURTHER EDIT:</strong></p>
  
  <p>Thank you again, and btw, your English is excellent (in response to your comment about bad English).</p>
  
  <p>I have changed my event handler from this:</p>
  
  <pre><code>$("emailInputBox").observe("keydown", function(event) {
      return submitViaEnter(event, submitSignupFormOne);
  });
  </code></pre>
  
  <p>to this:</p>
  
  <pre><code>$("emailInputBox").observe("keydown", function(event) {
      setTimeout(submitViaEnter.curry(event, submitSignupFormOne),0);
  });
  </code></pre>
  
  <p><code>submitViaEnter</code>:</p>
  
  <pre><code>function submitViaEnter(event, callback) {
  var code = event.keyCode;
  if (code == Event.KEY_RETURN) {
      event.stop();
      return callback(event);
  }
  return true;
  }
  </code></pre>
  
  <p>Seems to work but the problem now is that the browser is permitted to carry out the default action before running the <code>submitViaEnter</code> function which means the form is being submitted when I hit ENTER.</p>