Having issues getting this to work on submit, it functions properly when using
document.getElementById("gets").addEventListener("click", b_button);
but does not work when I try
document.getElementById("gets").addEventListener("submit", b_button);
Is there a way to make it work on submit instead of using click?
<form method="post">
<button type="submit" id="gets">Submit</button>
<p id="error"></p>
</form>
<script>
function b_button() {
document.getElementById("gets").disabled = true;
var time_meter = 10;
var runTimer = setInterval(function() {
if (time_meter <= 0) {
clearInterval(runTimer);
document.getElementById("error").innerHTML = "";
} else {
document.getElementById("error").innerHTML = 'counting ' + time_meter;
}
time_meter -= 1;
}, 1000);
setTimeout(function() {
document.getElementById("gets").disabled = false;
}, 10000);
}
// Change the event listener from click to submit
document.getElementById("gets").addEventListener("submit", b_button);
</script>