I'm performing the maintenance on a site with several forms with buttons of type SUBMIT and also normal buttons that call an onclick event that in FORMS is used to perform data validation and in other situations is used to do some action that moves in the database.
It happens that some users who access the site click the button several times to take some action, which is causing several INSERTS followed and incorrect before, for example, close the modal or redirect 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 on the onclick event and then turn it back on.
I tried this way but it did not work:
$('button').click(function() {
this.prop('disabled',true);
setTimeout(function(){
this.prop('disabled', false);
}, 5000);
});
I looked at multiple ways to prevent double click, including link that focuses especially in this matter. However, the ways I have found so far will make me have to go to each button on the site (it should have about 200 buttons, the site is big) and go putting this disable function one by one.
What should I change to the above code to work as I ordered?