简体   繁体   中英

how to disable a button when all the checkboxes in grid are disable or un checked using JavaScript/Jquery?

I have a grid in which I have 1 coulmns has checkboxes .I want to disable a button when all the checkbox are disabled or unticked(uncheked) using JavaScript or jQuery?

.Aspx File

<asp:TemplateField HeaderText="Cancel SO Line Item">
        <ItemTemplate>
        <asp:checkbox ID="cbSOCan" runat="server" ViewStateMode="Enabled" EnableViewState="true"></asp:checkbox>
         </ItemTemplate>

     <asp:LinkButton CssClass="btn btn-primary" ID="btnCancelItem" runat="server" CausesValidation="False"OnClientClick="return Confirmationbox();">&nbsp;Cancel Item</asp:LinkButton>
 <asp:HiddenField id="hdnval" value=0 runat="server"/>

GRID

You can do something like the following, but you'll need to update it with more specific selectors so it doesn't affect all checkboxes and buttons:

JS Fiddle

$('input[type=checkbox]').change(function(){
    var count = $('input[type=checkbox]:checked').length;
    $('button').prop('disabled', count == 0);
});

And if you need it on load as well:

JS Fiddle

$('input[type=checkbox]').change(function(){
    disableCheckbox();
});

disableCheckbox = function() {
    var count = $('input[type=checkbox]:checked').length;
    $('button').prop('disabled', count == 0);
};

disableCheckbox();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM