Skip to content

Instantly share code, notes, and snippets.

@willywg
Created Jul 1, 2019
Embed
What would you like to do?
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