Reputation: 5861
Greeting,
if I have asp.net checkboxlist control :
<asp:CheckBoxList id="list1" runat="server">
<asp:ListItem>One</asp:ListItem>
<asp:ListItem>Two</asp:ListItem>
<asp:ListItem>Three</asp:ListItem>
</asp:CheckBoxList>
how to get the text for second item which is (Two) and has index 1 using jquery when it is check or by passing the index of it?
Upvotes: 0
Views: 1938
Reputation: 3126
The checkbox items are given IDs in the following order:
Prefix the ID with the IDs of any <asp:Content ...>
tags that they are sitting in.
You can then reference them from jQuery easily:
if($('#list1_1').attr('checked')) {
// the second item is ticked, do something
}
If you are unsure of the ID given to each checkbox, then do a View Source on the page to check.
You could also write a simple function to do this:
function isListItemChecked(listIndex, listID) {
return ( $('#'+listID+'_'+listIndex).attr('checked')==true );
}
Upvotes: 1