JSFiddle - React, Tailwind, and code Playground
HTML
<button onclick="submitForm()">Submit Form</button>
JavaScript
// Setup variable for easy tracking!!!
var timesSubmitted = 0, timeCounter = 60 * 1000, Timer = null;
// Call function to submit form
function submitForm() {
// Check if user has submitted form more than 5 times
if (timesSubmitted < 5) {
// If timer has yet to be started... Start it!
if (Timer === null) {
Timer = setTimeout(
function() {
// Setup alert so user knows they can continue to submit form
if (timesSubmitted > 0) { alert('Submissions Reset'); }
timesSubmitted = 0;
},
timeCounter );
}
// Add for submission to counter
timesSubmitted++;
}else{
// Alert user they can not sumbit anymore!
alert('You may only submit this from 5 times per minute!');
}
}