I want to disable submitting form twice. Users often double click on submit button and then form is submitted twice. I already tried following Javascript, but does not work:
const btn = document.querySelector("#buttonid");
btn.addEventListener("dblclick", (e) => {
e.preventDefault();
});
const button = document.querySelector("#buttonid");
button.addEventListener("click", (e) => {
document.getElementById("buttonid").disabled = true;
});
$('#buttonid').prop("disabled", true);
<button ondblclick="this.disabled=true;">submit</button>
2
Answers
You can disable the button on after a single click.
Use the onsubmit form event. In this way the button wont get disabled on validation errors, only when submited.