Disable form submission when I press enter because I use Ajax functionality

I am using the ajax function. When I select any offer using the enter key, the form is automatically submitted because the submit button is automatically focused. Is there a way to select an ajax offer using the enter key, and also send a form using the enter key. Something like, when I enter the values ​​of all fields, then only the submit button is turned on.

+5
source share
3 answers

What do you call your Ajax function? It must be inside the submitform event handler . And then, if you have a returned event handler false, it will not be sent normally:

<form onsubmit="doAjaxSubmit(); return false;">
  ...
</form>
+4
source

You can determine which key is pressed using the method .keypress(). From this, you should be able return false;to submit the form and do your ajax stuff on the back of the instructions if:

http://api.jquery.com/keypress/

+2
source

You can have the form onSubmitreturn trueif all fields have values ​​or falseif they do not.

+1
source

All Articles