I want to activate the ENTER key for form submission.

Let’s see! the part of submitting a form by pressing the enter key is simple.

You simply have to place an action attribute on the

tag. The action indicates where the form should be sent and if it does not have it, the form is not sent anywhere, therefore a behavior is not applied to the fact of pressing the enter key on a field of the form.

If you don’t want the form to be sent to any other page, then you should at least put an action to the # value, which is like indicating the current page.

Now, the behavior that you want is not just to send the form anywhere, but to execute a Javascript function that performs a check. Then things change.

To get what you want, you have to call that function when you detect a form submission and you have to do that using Javascript. You detect the form submission, then you stop the default submission behavior and finally you call your function.



See also  String treatment in Javascript
Loading Facebook Comments ...
Loading Disqus Comments ...