Skip to content

Instantly share code, notes, and snippets.

@cjfarrelly
Created November 18, 2014 09:29
Show Gist options
  • Save cjfarrelly/2628c786f4a5af5a48d7 to your computer and use it in GitHub Desktop.
Save cjfarrelly/2628c786f4a5af5a48d7 to your computer and use it in GitHub Desktop.
Javascript function to check/uncheck all checkboxes in a checkboxlist, this also allows for normally functionality
function cblNamesChecked(event) {
var checkBoxList = document.getElementById("<%=cblNames.ClientID %>");
var checkBoxes = checkBoxList.getElementsByTagName("input");
event = event || window.event;
var target = event.target || event.srcElement;
if (target.id == "cblNames_0") {
for (var i = 0; i < checkBoxes.length; i++) {
checkBoxes[i].checked = target.checked;
}
}
}
<asp:CheckBoxList ID="cblNames" runat="server" CellPadding="0" OnClick="cblNamesChecked(event)" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment