0

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?

2
  • Duplicate of stackoverflow.com/questions/3560062/…, asked by the same poster approx 1 hour ago. Please don't re-post the same questions in rapid succession. Commented Aug 24, 2010 at 21:44
  • @mikemanne instead of writing what you wrote answer my other post here to get more points and to show out your expertize here is the port: stackoverflow.com/questions/3533824/… by the way I post this question before I got complete answer there !!! Commented Aug 25, 2010 at 3:00

1 Answer 1

1

The checkbox items are given IDs in the following order:

  • list1_0 => "One"
  • list1_1 => "Two"
  • list1_2 => "Three"

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 );
}
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.