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
  • 2,810
  • 14
  • 54
  • 109

2 Answers2

1

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

Devon
  • 32,773
  • 9
  • 61
  • 91
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
  • 1,957
  • 1
  • 16
  • 25