Hi,

I've been searching the web for an answer to this but haven't been
able to find one.

I have a form which is using an image as it's submit button and I want
users to be able to submit the form by pressing enter.  Simple enough:

// submit the login form if the user hits enter
$('.login_input').keypress(function(event) {
  if(event.keyCode == 13) {
    $('#login').submit();
  }
});

That works fine.  However, if the user is presented with a list of
options for the text input by their browser and they use the up and
down arrows keys to highlight, then enter to select an option the form
gets submitted.  Not ideal!  So, my question is how can I identify the
last key press before the user hits enter?  Ideally my logic will be
something like:

$('.login_input').keypress(function(event) {
  if(LAST KEYPRESS IS NOT UP OR DOWN ARROW) {
    if(event.keyCode == 13) {
      $('#login').submit();
    }
  }
});

Hopefully, that makes sense!  Many thanks in advance for any help.

Rob.

Reply via email to