views:

266

answers:

2

Hi...

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 form, 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...

+6  A: 

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

Jan Hančič
Thanx alot man... helped
Camran
no problem, glad to help!
Jan Hančič
A: 

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

(From: http://stackoverflow.com/questions/1818249/form-with-no-action-and-where-enter-does-not-reload-page/2189020#2189020)

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>
GenericMeatUnit