Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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

share|improve this question
    
How do they look like? DO you want to uncheck all of them? –  PSL May 22 '13 at 2:58
    
yes i want to uncheck all –  user545359 May 22 '13 at 3: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 4:29

4 Answers 4

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);
share|improve this answer
    
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 2: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 3:20

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.

share|improve this answer

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);
}
share|improve this answer

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.

Many Thanks Anna

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.