JS / JQuery form submission delay?

I implemented this locksubmit plugin http://blog.leenix.co.uk/2009/09/jquery-plugin-locksubmit-stop-submit.html , where it changed the display state of the button to disable. Then I want the form to be delayed for a few seconds before being posted to the form URL.

What do I need to add or change to postpone the message form after the user clicks the submit button?

Thanks!

+4
source share
2 answers

Cancel the default form submission behavior and run the timeout at the same time:

$('form').submit(function (e) { var form = this; e.preventDefault(); setTimeout(function () { form.submit(); }, 1000); // in milliseconds }); 

This should be compatible with the locksubmit plugin.

See the demo here: http://jsfiddle.net/7GJX6/

+21
source

I think this is what you are looking for - change lockSubmit() as such:

 jQuery(':submit').lockSubmit(function(){ setTimeout(5e3); // fancy 5 seconds }); 

And with options objects:

  jQuery(':submit').lockSubmit({ submitText: "Please wait", onAddCSS: "submitButtons", onClickCSS: "submitButtonsClicked" },function(){ setTimeout(5e3); })); 

Basically, javascript should wait until all arguments are resolved before the body starts. By setting a timeout during the argument, we delay the return.

0
source

Source: https://habr.com/ru/post/1341085/


All Articles