I have the following code to do select all on an ASP check box list:
<script type="text/javascript">
$(document).ready(function () {
$('.myCheckBoxList :checkbox').eq(0).click(function () {
var cbl = document.getElementById('<%=cbl_list1.ClientID %>').getElementsByTagName("input");
// If Checked
if (this.checked) {
for (i = 0; i < cbl.length; i++)
cbl[i].checked = true;
}
// If Unchecked
else {
for (i = 0; i < cbl.length; i++)
cbl[i].checked = false;
}
});
});
</script>
<asp:CheckBoxList ID="cbl_list1" runat="server" AppendDataBoundItems="true" CssClass="myCheckBoxList" >
<asp:ListItem Text="Select All" Value="Select All" />
<asp:ListItem Text="1" Value="1" />
<asp:ListItem Text="2" Value="2" />
<asp:ListItem Text="3" Value="3" />
</asp:CheckBoxList>
I would like to add multiple check box lists that use the same code. How can I inherit the client id with out hardcoding it into the js (ie: getElementById('<%=cbl_list1.ClientID %>')