Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable button working on click

Tags:

jquery

$(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

like image 823
user354625 Avatar asked Jun 24 '10 17:06

user354625


2 Answers

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.

like image 132
ryanulit Avatar answered Nov 15 '22 09:11

ryanulit


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;
    }
});
like image 27
user113716 Avatar answered Nov 15 '22 10:11

user113716