2

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?

1
  • why using setTimeout ? Commented Sep 10, 2010 at 7:50

5 Answers 5

8
setTimeout(function() {
    $('#btn').attr('disabled', 'disabled');
}, 1);
Sign up to request clarification or add additional context in comments.

2 Comments

my controller code is not calling. its like when it disable the button the request is stopped?
I've found that disabling a button in the click event prevents the form being submitted in some versions of IE. I've posted a solution stackoverflow.com/questions/2294041/…
6

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);

Comments

1
setTimeout($('#btn').attr('disabled', 'disabled),1);
$("#btn").removeAttr('disabled', disabled')

Comments

0

This should work.

$("#loginButton").click(function (e) {
        var btn = $(this).clone();
        btn.prop("disabled", true)
        $(this).hide();
        $(this).after(btn);
        return true;
    });

Comments

-1

try this:

setTimeout($('#btn').attr('disabled', 'disabled'), 1);
return true;

1 Comment

You're passing the jQuery object to setTimeout, IMO, it is not a callable, nor a string to eval :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.