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.
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.
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.
Disallow enter key anywhere$(document). on("keydown", "form", function(event) { return event. key != "Enter"; });
We use the preventDefault() method with this event to prevent the default action of the form, that is prevent the form from submitting.
$('input').keydown(function(e){
return e.keyCode !== 13;
});
... I don't recommend doing this, by the way.
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;">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With