0

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!

1 Answer 1

1

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);
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.