Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JS /JQuery Form Submit Delay?

I've implemented this 'locksubmit' plugin http://blog.leenix.co.uk/2009/09/jquery-plugin-locksubmit-stop-submit.html where it changes the display state of the button to disabled. I then want the form to be delayed by a few seconds before posting to the form URL.

What would I have to add in or modify to delay the form "post" once the user has clicked the submit button?

Thanks!

like image 895
jeremycollins Avatar asked Nov 29 '22 17:11

jeremycollins


1 Answers

Cancel the default form submit behaviour, and start a 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 a demo here: http://jsfiddle.net/7GJX6/

like image 86
David Tang Avatar answered Dec 05 '22 07:12

David Tang