I am trying to fix a form double submit by disabling the submit button temporarily and changing the submit button value to "processing..." so the user knows what is going on.
The disable works onClick
and the "Submit" value changes to "processing...", however I am unable to change the value back to "Submit" after the setTimeout
function has ended.
Does anyone know how I could go about doing this?
$(function() {
$("#submit_btn").click(function() {
$("#submit_btn").attr("disabled", "disabled");
this.value = "Processing...";
setTimeout(function() {
this.value = "Submit"; //<- this line doesn't work
$("#submit_btn").removeAttr("disabled");
}, 5000);
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input id="submit_btn" type="submit" value="Submit" />