jQuery form submit, prevent from sending multiple times after first submit
delay, javascript, jquery, submit
Solution
"So i want after a submit, that the next submit does nothing for a few seconds."
If you mean that you want the user's second and subsequent submit attempts to be ignored until after a certain number of seconds you can do that in a number of ways. Here's the first that came to mind:
var allowSubmit = true;
$("#updatestock_form").submit(function(e){
if (!allowSubmit) return false;
allowSubmit = false;
setTimeout(function(){ allowSubmit = true; }, 5000);
// your existing submit code here
// requesting my data..
});
That is, have a flag that indicates whether submit is currently allowed. On the submit event if that flag is false just return `false` immediately to cancel the submit event. Otherwise (if it is currently `true`) set the flag to `false`, set a timeout to change the flag back after, say, 5 seconds, and then carry on with your existing submit code.
Problem
I am making a webapplication that uses a jquery submit to request some data, but i don't want people submit the form multiple times after they submit the first time. So i want after a submit, that the next submit does nothing for a few seconds. ``` $("#updatestock_form").submit(function(e){ // requesting my data.. }); ``` How can i achieve this?