I need to uncheck all the Reject checkbox's on clicking Approve checkbox header and vice versa. How can I achieve this using jquery/javascript.
My HTML code is as follows
<asp:TemplateField >
<HeaderTemplate>
Approve
<br />
<input id="ChkAllApprovedItems" type="checkbox" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkApproval" Checked='<%#Eval("IsApproved").ToString()=="1"?true:false %>' runat="server" onclick="EnableApprove(this,this.checked);" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField >
<HeaderTemplate>
Reject
<br />
<input id="ChkAllRejectedItems" type="checkbox" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkReject" Checked='<%#Eval("IsRejected").ToString()=="1"?true:false %>' runat="server" onclick="EnableReject(this,this.checked);" />
</ItemTemplate>
</asp:TemplateField>
Can someone help me with a sample code.
Thanks.
Here's a pretty simple example:
You can change other check-box attribute based on main checkbox. JS Fiddle
$("#master_checkbox").change(function(){
// if checkbox is checked then chek all
if($(this).attr('checked')) {
$(".change_me").attr('checked', 'checked');
}
// uncheck all
else {
$(".change_me").removeAttr('checked');
}
});
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.