Reputation: 281
I'm trying to check to see if the aspboxes are checked in js. Can I set an ID number to the listItems and check each one by one?
<asp:CheckBoxList ID="CheckBoxList1" runat="server">
<asp:ListItem Text="Asset Classes" value="Asset Classes"></asp:ListItem>
<asp:ListItem Text="Asset Types" Value="Asset Types"></asp:ListItem>
<asp:ListItem Text="Asset Manufactuerer" value="Asset Manufactuerer"></asp:ListItem>
<asp:ListItem Text="Asset Voltage Class" Value="Asset Voltage Class"></asp:ListItem>
</asp:CheckBoxList>
Thanks!
Upvotes: 0
Views: 57
Reputation: 5899
No you can't. CheckBoxList's ListItem doesn't have id attribute.
But you can access each item by index.
function MyFunction() {
var CheckBoxList1 = document.getElementById('CheckBoxList1');
var checkBoxItems = CheckBoxList1.getElementsByTagName("input");
for (var i = 0; i < checkBoxItems.length; i++) {
if (checkBoxItems[i].checked) {
alert(checkBoxItems[i].value);
}
}
}
Upvotes: 1