Created
July 1, 2019 17:33
-
-
Save willywg/9d7739f368c8c58aa761882d1f5cc310 to your computer and use it in GitHub Desktop.
Prevent multiple submits when clicked a submit button
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form action='/'> | |
<button class="prevent-multiple-submit" type="submit">Create</button> | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function disableButton(event) { | |
event.target.setAttribute('disabled', 'disabled'); | |
event.target.form.submit(); | |
} | |
var preventButtons = document.getElementsByClassName('prevent-multiple-submit'); | |
var i; | |
for (i = 0; i < preventButtons.length; i++) { | |
preventButtons[i].addEventListener('click', disableButton); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment