Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Safari: Disable form-submit on Enter? [duplicate]

Following problem:

On my site, I have two forms. One for login and one for main data. I have only one submit button in the mainform. The loginform is submitted via js on mainform submit.

This works fine. But in Safari I can press Enter while my focus is inside the login form. This will send the login form without the mainform, so I get an error (It redirects me to a plain view of a json I request on submit).

Is it possible to disable the "on enter pressed" action?

like image 368
Newbie Avatar asked Dec 15 '09 10:12

Newbie


2 Answers

If you say you use anyway the JS to submit the data in the form why not cancel the default behaviour of the browser with <form onsubmit="return false;">. This way no matter if you press the submit button or press enter in an input it won't be sent. The onsubmit="return false" shouldn't interfere with calling the submit() method on the form from JS.

like image 178
khel Avatar answered Oct 14 '22 05:10

khel


You can add the onsubmit handler for your login form. This handler can help you prevent submitting your form (and for example move your cursor to the next empty field in the forms);

<form onsubmit="do_some_function(); return false;" ></form>

To prevent form from submition, return false in your onsubmit handler;

like image 2
nemisj Avatar answered Oct 14 '22 05:10

nemisj