Reputation: 10448
On submit button i want to disable the button so user does not click more than once. im using jquery for that but its not working, my code is
setTimeout($('#btn').attr("disabled", true), 1);
return true;
button get disabled but my controller does not call. what am i doing wrong?
Upvotes: 2
Views: 8071
Reputation: 1
This should work.
$("#loginButton").click(function (e) {
var btn = $(this).clone();
btn.prop("disabled", true)
$(this).hide();
$(this).after(btn);
return true;
});
Upvotes: 0
Reputation: 11
setTimeout($('#btn').attr('disabled', 'disabled),1);
$("#btn").removeAttr('disabled', disabled')
Upvotes: 1
Reputation: 7526
I don't see much reason to use timeout, I'd just go with
$('#btn').attr('disabled', 'disabled');
return true;
or more precisely,
$('#btn').click( function (e) {
$(this).attr('disabled', 'disabled');
});
is all you need.
And being a bit wicked and esoteric :P
return !!$('#btn').attr('disabled', 'disabled');
and that, was just for fun. Don't do it in your code! :)
Edit: with a recent version of jQuery, you can make it
$('#btn').attr('disabled', true);
Upvotes: 6
Reputation: 1038810
setTimeout(function() {
$('#btn').attr('disabled', 'disabled');
}, 1);
Upvotes: 8
Reputation: 1612
try this:
setTimeout($('#btn').attr('disabled', 'disabled'), 1);
return true;
Upvotes: -1