Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent Users from submitting form by hitting enter #2 [duplicate]

Well in a previous question I asked the same thing, but the answer that i doesn't prevent a submit when the user is in a text-box.

So basically what i need is the ability to keep a person from submitting a form unless the explicitly click the submit button.

edit:

basically the main reason for doing this is that this is an employer survey. the people on this won't be the most technically savvy, and the client i'm making this for has requested this.

like image 598
DForck42 Avatar asked May 28 '09 23:05

DForck42


People also ask

How do you prevent form submit on Enter?

To prevent form submission when the Enter key is pressed in React, use the preventDefault() method on the event object, e.g. event. preventDefault() . The preventDefault method prevents the browser from refreshing the page when the form is submitted.

How do you stop re submitting a form after clicking back button?

As someone already mentioned, if you switch the form to a post method and switch the Servlet to a doPost, you won't have this issue anymore. You can check if the user clicked the back button, disable form if true. Another way is by storing a cookie which you check on page load, if it exists you can disable the form.

How do you prevent form submit on Enter in JQuery?

Disallow enter key anywhere$(document). on("keydown", "form", function(event) { return event. key != "Enter"; });

How Stop form submit on click of submit button?

We use the preventDefault() method with this event to prevent the default action of the form, that is prevent the form from submitting.


2 Answers

$('input').keydown(function(e){
    return e.keyCode !== 13;
});

... I don't recommend doing this, by the way.

like image 184
James Avatar answered Oct 28 '22 19:10

James


i set the form to onsubmit="return false" and did this

<input type="button" value="Submit" onClick="document.Survey.submit()" style="font-size: 1.25em;">
like image 35
DForck42 Avatar answered Oct 28 '22 19:10

DForck42