user354625
user354625

Reputation: 557

Disable button working on click

$(document).ready(function() {
     $("#FieldsetID").each(function() {
                 $('.Isubmit').attr('disabled', 'disabled');
            });
});

the button showing as disabled but when I click on that its doign action?

is that something i am doing wrong?

thanks

Upvotes: 6

Views: 11176

Answers (5)

Suleman Mirza
Suleman Mirza

Reputation: 925

Well an easiest way is to find if the click button have disabled class if it have return false, for example:

 $('.button1').click(function () {
 if ($(this).hasClass('disabled')) {
     return false;
 } else {
     //do whatever you want when element is clicked
 }

});

Upvotes: 0

Kshitiz
Kshitiz

Reputation: 2743

http://forum.jquery.com/topic/disable-enable-button-in-form

Try this to enable it. again

$(document).ready(function(){
    $("input[type=submit]").attr("disabled", "disabled");

    if ( $('#nome').is(":empty") ) {
        alert ("verdadeiro");
    }
    else {
        alert ("entrou no if");
        $("input[type=submit]").removeAttr("disabled");
    }

});

Upvotes: 1

user113716
user113716

Reputation: 322462

For some reason, IE doesn't prevent the event from bubbling when you click a disabled submit button.

I assume you have some other event handler on an ancestor that is therefore being triggered.

In that ancestor's event handler, it looks like you'll need to test to see if the submit button was clicked and if it is disabled. If so, you'll return false; to prevent the code from running, or the submit from occurring, or whatever.

       // Not sure if this is the right event, but you get the idea
$( someSelector ).click(function( event ) {
    var $target  = $(event.target);
                  // check to see if the submit was clicked
                  //    and if it is disabled, and if so,
                  //    return false
    if( $target.is(':submit:disabled') ) {
        return false;
    }
});

Upvotes: 2

Teja Kantamneni
Teja Kantamneni

Reputation: 17472

Altough untested, i think when you are selecting elements by id, you don't need to use each as it returns one element, and when you are selecting using class you have to use each, try using each on disabling selector and see.

Upvotes: 1

ryanulit
ryanulit

Reputation: 5001

I don't think you can run an .each() function on a unique element. It's unique because you are using an #id selector.

You just need to do this:

$(document).ready(function() {
     $('#FieldsetID .Isubmit').attr('disabled', 'disabled');
});

Now the buttons shouldn't be clickable.

Upvotes: 4

Related Questions