0

I have asp.net checkboxlist control that bounded to a data source so the number of items in the control are different from one to to another time.

I have this function:

 $('#<%=chkListGroups.ClientID %> input:checkbox:checked').siblings('label').text(); 

this function will return all texts for all selected items in the control as a one string.

I'm looking for a way that when I check a check box from the ckeckboxlist control will return only last checked checkbox.

Please advice me how to do this using jquery.

1 Answer 1

1

I think this is what you're after, using a .change() handler:

$('#<%=chkListGroups.ClientID %> input:checkbox').change(function() {
   alert($(this).siblings('label').text());
});

This would alert the status of each one as it's checked/unchecked, you can use those values however you want.

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you for your help. I tested your code but it is only return an alert with string="checked" and I check more then one check box will return the alert as much as how many items I checked. what I'm looking for exactly is to return the last checkedbox text by the user and go through all items and check every items text will make my problem harder to solve because I need to user the result as soon as I get it. Thank you,
@Eyla - The alert will have the text in it, that's the $(this).siblings('label').text() part above...it'll alert every time you check yes, you're looking to run once at the end of a check session or something like that?
I checked the code few times but the code only return checked string no more. I want the code return only the text of the item checked no more than that. for example when I check second item it will return the text of the second item and if I check fourth item it will return text of fourth item.
@Eyla - Gotcha, try the updated answer :) You can add a if(this.checked) before the alert() if you don't want it to show when unchecking.

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.