Skip to content Skip to sidebar Skip to footer

Disable Button After Post Using Js/jquery

I would like to have a function to add an onclick event to my form buttons to get them disabled in order to avoid double posting.

Reference:click, attr

Solution 2:

$(button).attr('disabled', true);

Solution 3:

<button onclick="this.disabled='disabled'"type...>

Solution 4:

If you want to just target a button:

$('#buttonID').click(function(){
    $(this).attr('disabled', 'disabled');
});

If you want a function:

functiondiableButton(bID){
    $(bID).attr('disabled', 'disabled');
}

Call it using something like:

$('#myform').submit(function(){
    disableButton($('input[type=submit]', this));
});

Post a Comment for "Disable Button After Post Using Js/jquery"