hi everybody
i have this code
$('#<%=chkAdminRole.ClientID%>').click(function () { if ($(this).is(':checked')) { $('#<%=chkConvertRole.ClientID%>').attr('checked', true); $('#<%=chkReplayRole.ClientID%>').attr('checked', true); } else if ($(this).not(':checked')) { $('#<%=chkConvertRole.ClientID%>').attr('checked', false); $('#<%=chkReplayRole.ClientID%>').attr('checked', false); } });
the code work fine when click check box at first time , but when click again does not work ,
please help
thanks
Try using prop instead of attr to check and uncheck the checkboxes.
Please use the below code
<script> $(document).ready(function () { $('#<%=chkAdminRole.ClientID%>').click(function () { if ($(this).is(':checked')) { $('#<%=chkConvertRole.ClientID%>').prop('checked', true); $('#<%=chkReplayRole.ClientID%>').prop('checked', true); } else if ($(this).not(':checked')) { $('#<%=chkConvertRole.ClientID%>').prop('checked', false); $('#<%=chkReplayRole.ClientID%>').prop('checked', false); } }); }); </script>
Complete Code:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="//code.jquery.com/jquery-1.11.0.min.js"></script> <script> $(document).ready(function () { $('#chkAdminRole').click(function () { if ($(this).is(':checked')) { $('#chkConvertRole').prop('checked', true); $('#chkReplayRole').prop('checked', true); } else if ($(this).not(':checked')) { $('#chkConvertRole').prop('checked', false); $('#chkReplayRole').prop('checked', false); } }); }); </script> </head> <body> <input type="checkbox" id="chkAdminRole" /> <input type="checkbox" id="chkConvertRole" /> <input type="checkbox" id="chkReplayRole" /> </body> </html>
it is work fine,thanks
haitham shaaban
it is work fine,thanks
![]()
You are welcome and Glad to be of help