I've got a bunch of checkboxes generated by an asp.net CheckBoxList control. I want to get the text the user sees next to the control on the page.
With similar controls, like RadioButtonList, I've been able to get their values in jQuery by doing this:
var selected = $("input:checked[id*='" + Control.id + "']");
and then looping through and getting the value:
var whatIwant = selections[i].value;
(In this case, that "value" will be the text I want).
But - CheckBoxList renders differently. For each ListItem there's not only the input, but an html tag like so:
<input id="ctl00_ContentPlaceHolder1_ConsultedList_0" type="checkbox" name="ctl00$ContentPlaceHolder1$ConsultedList$0" />
<label for="ctl00_ContentPlaceHolder1_ConsultedList_0">Other service providers</label>
As you can see, the input tag itself, which is what my nice little jQuery query finds, doesn't include the info I want: "Other service providers". That's on the label tag.
Can anyone think of a good solution for this - maybe a good way of making the CheckBoxList render the text I need in the input tag, or some clever jQuery to find the labels that correspond to the selected inputs?