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();"> Cancel Item</asp:LinkButton>
<asp:HiddenField id="hdnval" value=0 runat="server"/>
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:
$('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:
$('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.