Link to home
Start Free TrialLog in
Avatar of lulu50
lulu50Flag for United States of America

asked on

Stop submitting the form everytime I hit on enter

Hi,

I have a form, that submit the data everytime I hit on enter.  

How can I stop, the form from submitting the data if I hit on enter?

Thanks,
Lulu
Avatar of Big Monty
Big Monty
Flag of United States of America image

you can use this code:

$(document).ready(function() {
  $(window).keydown(function(event){
    if(event.keyCode == 13) {
      event.preventDefault();
      return false;
    }
  });
});

Open in new window

Returning false is the keyword to prevent duplicate entrieswhen key is pressed.

if ($textbox.val().length > 0 && e.keyCode == 13) {
    $textbox.parent('form').submit();
    return false;
}

Open in new window

Is there any script that is submitting the form on press of enter?  The selector may be too generic.
Avatar of lulu50

ASKER

Big - I tried your code did not work, not sure why

Sammy - what is $textbox? got an error on that it says undefined.

Anthony - no I don't have a script that is submitting my form.
ASKER CERTIFIED SOLUTION
Avatar of Big Monty
Big Monty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lulu50

ASKER

Big,  

GREAT!!!!!

That did the trick.  

Thank you for your help
Avatar of lulu50

ASKER

Thank you
my pleasure!

Happy Coding :)