I have an asp.net checkbox list and the values of checkboxlist are binded from database. my requirement is to uncheck the checkboxes on a button click. Can someone please suggest me a way on how to uncheck the checkboxes using javascript or jquery. Thanks
            Asked
            
        
        
            Active
            
        
            Viewed 9,951 times
        
    0
            
            
        - 
                    How do they look like? DO you want to uncheck all of them? – PSL May 22 '13 at 02:58
- 
                    yes i want to uncheck all – user545359 May 22 '13 at 03:00
- 
                    You can do: $('#button').click(function() { $('input[type=checkbox]').prop('checked', true); }); -- the selector will scan all of the input controls and filter it via 'checkbox' type, then internal code will switch their 'checked' property to 'true'. – KevinIsNowOnline May 22 '13 at 04:29
4 Answers
1
            
            
        Possible Similar QUestion
    //Assuming you have this object model structure in your ASPX page.
<input type="text" name="openid_username" />
<input type="text" name="openid_identifier" />
Upon screen render, it gets  translated to:
<asp:TextBox ID="ctl00_ContentPlaceHolder1_ctl00_openid_username" runat="server"></asp:TextBox>
<asp:TextBox ID="ctl00_ContentPlaceHolder1_ctl00_openid_identifier" runat="server"></asp:TextBox>
<input type='button' id='myButton' value='Check Button'>
You can set the checked property of the checkboxes via below jquery code:
$('#myButton').click(function() {
  $('input[name$=openid_username]').prop('checked',true);
$('input[name$=openid_identifier]').prop('checked',true);
  });
Also, please see this jsFiddle link.
 
    
    
        Community
        
- 1
- 1
 
    
    
        KevinIsNowOnline
        
- 773
- 4
- 10
0
            
            
        Give the checkboxes a css class say .mycheckbox
// On:
$(".mycheckbox").checked(true);
// Off:
$(".mycheckbox").checked(false);
// Toggle:
$(".mycheckbox:checked").checked(false);
$(".mycheckbox:not(:checked)").checked(true);
 
    
    
        Tom Fobear
        
- 6,729
- 7
- 42
- 74
- 
                    hi tom, the checboxes are binded dynamically from database. will this solution work in such case? thanks for your reply – user545359 May 22 '13 at 02:56
- 
                    user545359, yes it should, it will not mangle the CssClass name. Asp.net will mangle IDs so if you stick to that you should be fine. – Tom Fobear May 22 '13 at 03:20
0
            
            
        Jquery
function checkAll(formname)
{
  var checkboxes = new Array(); 
  checkboxes = document[formname].getElementsByTagName('input');
  for (var i=0; i<checkboxes.length; i++)  {
    if (checkboxes[i].type == 'checkbox')   {
      checkboxes[i].checked = false;
    }
  }
}; 
$(document).ready(function(){
$('#unCheck').click(function () {
         checkAll("form1");
      });
});
HTML
  <form id="form1" runat="server">
    <div>
    <asp:CheckBoxList id="check1" AutoPostBack="True" TextAlign="Right" runat="server">
    <asp:ListItem>Item 1</asp:ListItem>
    <asp:ListItem>Item 2</asp:ListItem>
    <asp:ListItem>Item 3</asp:ListItem>
    <asp:ListItem>Item 4</asp:ListItem>
    <asp:ListItem>Item 5</asp:ListItem>
    <asp:ListItem>Item 6</asp:ListItem>
This will resolve your issue.
-1
            
            
        Put an html button:
<input type="button" value="Uncheck all" onclick="uncheckCheckboxes()" />
Write javascript function uncheckCheckboxes (assuming your checkboxlist id is cbl):
function uncheckCheckboxes()
{
   $("#<%# cbl.ClientID %> input").prop("checked",false);
}
 
    
    
        mshsayem
        
- 17,557
- 11
- 61
- 69
- 
                    not working below should work $("#<%=Checkbox1.ClientID %>").prop("checked",false); – Mahesh Mar 15 '17 at 01:50
 
     
    