I need to disable a button once it\'s clicked so the user can\'t click it more than once. (My application is written in MVC ASP.NET, I\'ve done this in a normal ASP.NET appl
$("selectorbyclassorbyIDorbyName").click(function () {
$("selectorbyclassorbyIDorbyName").attr("disabled", true).delay(2000).attr("disabled", false);
});
select the button and by its id or text or class ... it just disables after 1st click and enables after 20 Milli sec
Works very well for post backs n place it in Master page, applies to all buttons without calling implicitly like onclientClick
think simple
<button id="button1" onclick="Click();">ok</button>
<script>
var buttonClick = false;
function Click() {
if (buttonClick) {
return;
}
else {
buttonClick = true;
//todo
alert("ok");
//buttonClick = false;
}
}
</script>
if you want run once :)
To disable a submit button, you just need to add a disabled attribute to the submit button.
$("#btnSubmit").attr("disabled", true);
To enable a disabled button, set the disabled attribute to false, or remove the disabled attribute.
$('#btnSubmit').attr("disabled", false);
or
$('#btnSubmit').removeAttr("disabled");