Submit Form problem... Enter key
I have a form containing several drop lists and a text field, and a button...
When I click the button, an ajaxfunction is called... the ajax then calls a php function which gets results from a mysql db...
The problem is that I cant do the same thing by just hitting enter in the f开发者_StackOverfloworm, the page just gets refreshed...
That explained, I think the form gets submitted, but ignores the ajaxfunction when hitting enter, EVEN though i have " onSubmit="AjaxFunction();" in the form tag...
Any ideas?
Does anybody know a way to ignore the form submit when hitting enter? and maybe instead click the button when hitting enter?
Thanks...
change your onsubmit to onsubmit="return AjaxFunction();" and return false from your AjaxFunction. That will prevent the form from submiting.
A little late, I know, but here's another solution for your consideration..
(From: form with no action and where enter does not reload page)
Add this event to your text field. It will prevent a submission on pressing Enter, and you're free to add a submit button or call form.submit() as required:
onKeyPress="if (event.which == 13) return false;"
For example:
<input id="txt" type="text" onKeyPress="if (event.which == 13) return false;"></input>
精彩评论