0
I am performing maintenance on a site with multiple forms with buttons of type SUBMIT and also normal buttons that call an onclick event that in FORMS is used to perform the validation of the data and in other situations is used to make some action that moves the database.
It is happening that some users who access the site click several times on the button to perform some action, which is causing several INSERTS followed and incorrect before, for example, closing the modal or redirecting to the other page at the end of the execution of the script.
I want to create a function in my scripts.js so that when any button is clicked, it gets disabled for a few seconds and run what was set directly in the onclick event and then activate it again.
I tried it this way but it didn’t work:
$('button').click(function() {
this.prop('disabled',true);
setTimeout(function(){
this.prop('disabled', false);
}, 5000);
});
I searched on several sites ways to prevent double click, including http://www.the-art-of-web.com/javascript/doublesubmit/ that focuses primarily on this subject. However, the ways I’ve found so far will make me have to go on every button on the site (it must have 200 buttons, it’s great the site) and go putting this disable function one by one.
What I should change to the code above to work as I asked?
It worked perfectly as it should. Thank you :D
– WitnessTruth