I am looking for the neatest way to create an html form which does not have a submit button. That itself is easy enough, but I also need to stop the form from reloading itself when submission-like things are done (for example, hitting enter in a text field).
+2
A:
Add an onsubmit handler to the form (either via plain js or jquery $().submit(fn)), and return false unless your specific conditions are met.
Unless you don't want the form to submit, ever - in which case, why not just leave out the 'action' attribute on the form element?
K Prime
2009-11-30 07:08:48
+1
A:
Simply 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
2010-02-03 01:08:50
Thankyou for that. I am afraid the clarity of your answer made clear to me the correctness of an earlier answer so you don't get the accepted answer but you do get my gratitude and an upvote!
Matt Roberts
2010-02-03 20:16:21
Thank you. Glad to help. I was never one for the limelight anyway. ;)
GenericMeatUnit
2010-02-04 10:38:45