views:

69

answers:

3

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?

A: 

try this:

setTimeout($('#btn').attr('disabled', 'disabled'), 1);
return true;
Vaibhav Gupta
You're passing the jQuery object to `setTimeout`, IMO, it is not a callable, nor a string to `eval` :)
Shrikant Sharat
+2  A: 
setTimeout(function() {
    $('#btn').attr('disabled', 'disabled');
}, 1);
Darin Dimitrov
my controller code is not calling. its like when it disable the button the request is stopped?
Fraz Sundal
+2  A: 

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! :)

Shrikant Sharat