jQuery to select/deselect all items in a CheckBoxList.

vishalneeraj-24503
Posted by vishalneeraj-24503 under jQuery category on | Points: 40 | Views : 436

<asp:CheckBox runat="server" ID="selectAllCb" Text="Select All" />
<asp:checkboxlist runat="server" ID="containerCBL">
<asp:ListItem>Small</asp:ListItem>
<asp:ListItem>Large</asp:ListItem>
<asp:ListItem>Micro</asp:ListItem>
<asp:ListItem>Regular</asp:ListItem>
<asp:ListItem>Unknown</asp:ListItem>
<asp:ListItem>Other</asp:ListItem>
<asp:ListItem>Virtual</asp:ListItem>
</asp:checkboxlist>

<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>

<script type="text/javascript">
//hook to the document ready function
$(document).ready(function ()
{
//find the select all checkbox
var selectAll = $('#<%=selectAllCb.ClientID%>');

//hook onto select all checkbox's click event
selectAll.click(
function ()
{
//for all input types of checkbox
//for the container
//set the attribute to the value
//of select all checkbox
$("#<%=containerCBL.ClientID%> input[type='checkbox']").
attr('checked', selectAll.is(':checked'));
}
);
});
</script>

Comments or Responses

Login to post response