Skip to content

Instantly share code, notes, and snippets.

@willywg
Created July 1, 2019 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willywg/9d7739f368c8c58aa761882d1f5cc310 to your computer and use it in GitHub Desktop.
Save willywg/9d7739f368c8c58aa761882d1f5cc310 to your computer and use it in GitHub Desktop.
Prevent multiple submits when clicked a submit button
<form action='/'>
<button class="prevent-multiple-submit" type="submit">Create</button>
</form>
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