I want to run an Asp.net button click event (After clicking it) then disable it for 5 seconds and enable it again. I use this java script code but the click event code does not executed. What is wrong with it? I am new with js.
function lockoutSubmit(button) {
var oldValue = button.value;
button.setAttribute('disabled', true);
button.value = 'Wait 5 sec';
setTimeout(function () {
button.value = oldValue;
button.removeAttribute('disabled');
}, 5000)
}
html:
<asp:Button ID="Button1"
runat="server"
Text="Send"
onclientclick="lockoutSubmit(this)" />
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
You can try this:
function lockoutSubmit(button) {
var oldValue = button.value;
setTimeout(function () {
button.setAttribute('disabled', true);
button.value = 'Wait 5 sec';
}, 0);
setTimeout(function () {
button.value = oldValue;
button.removeAttribute('disabled');
}, 5000);
}
Method 2
check this out. https://jsfiddle.net/9ds9mL1v/5/
$("#Button1").click(function(){
var button =$(this);
var oldValue = $(this).value;
button.attr('disabled', true);
button.value = 'Wait 5 sec';
setTimeout(function () {
button.value = oldValue;
button.removeAttr('disabled');
}, 5000)
});
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0