Submit problem form ... Enter key

I have a form containing several lists of lists and a text box, as well as a button ...

When I click the button, the ajax function is called ... ajax then calls the php function, which gets the results from mysql db ...

The problem is that I cannot do the same, just by pressing Enter on the form, the page just refreshes ...

This is explained, I think the form is submitted, but ignores the ajax function when hit enter, EVEN, although I have "onSubmit =" AjaxFunction (); "in the form tag ...

Any ideas?

Does anyone know a way to ignore form submission at login? and maybe instead press the button at the entrance?

Thanks...

+6
html ajax php mysql forms
source share
2 answers

change your onsubmit to onsubmit = "return AjaxFunction ();" and return false from your AjaxFunction. This will prevent the form from submitting.

+7
source share

A little late, I know, but here is another solution for your consideration.

(From: form without any action and where input does not reload the page )

Add this event to your text box. This will prevent the submission when you press Enter, and you can add a submit button or call the .submit () form for free:

onKeyPress="if (event.which == 13) return false;" 

For example:

 <input id="txt" type="text" onKeyPress="if (event.which == 13) return false;"></input> 
0
source share

All Articles