0

I want enter to be pressed so the focus changes from the current to the next input. I've done this but i'm having a problem. The form submits when enter is pressed.

$('.length_input input[type=text], .qty').keypress(function(event) {
  if(event.which == 13) {
   //enter pressed
     active($(this));
   }
});

How do i allow enter to be pressed on inputs but prevent the form for submitting? I have a submit button to submit the form.

user892134
  • 3,078
  • 16
  • 62
  • 128

2 Answers2

1

event.preventDefault() should be used to prevent the default action of enter.

Devon Bessemer
  • 34,461
  • 9
  • 69
  • 95
0

You need to prevent the default action on the form.

form.addEventListener('submit', function (event) {
    event.preventDefault();
});
$('.length_input input[type=text], .qty').keypress(function(event) {
    if(event.which == 13) {
        //enter pressed
        active($(this));
    }
});
Micah Henning
  • 2,125
  • 1
  • 18
  • 26