I have a databound Checkboxlist in asp.NET with DataTextField and DataValueField.
Now if i select a single item in that list, i need to have the value of only that item.
I found lots of solutions to find the values of all selected items but that is not what i need.
The only value i need is the one i justed selected or deselected.
Is there a way to get this value with jQuery code? For example in an alert like in the code below.
$("#checkboxlist").click(function () {
alert('value of the item that just got (de)selected');
});
Thanks alot!
UPDATE:
This is the html part:
<span id="checkboxlist">
<input id="checkboxlist_0" type="checkbox" name="checkboxlist$checkboxlist_0" value="11" />
<label for="checkboxlist_0">Item 1</label><br />
<input id="checkboxlist_1" type="checkbox" name="checkboxlist$checkboxlist_1" value="12" />
<label for="checkboxlist_1">Item 2</label><br />
<input id="checkboxlist_2" type="checkbox" name="checkboxlist$checkboxlist_2" value="13" />
<label for="checkboxlist_2">Item 3</label><br />
<input id="checkboxlist_3" type="checkbox" name="checkboxlist$checkboxlist_3" value="14" />
<label for="checkboxlist_3">Item 4</label><br />
</span>
This code should work (Attribute Ends with selector):
asp:CheckBoxListwill be rendered as some element (in your case it should bespan) with ID likectl00_contenttop_checkboxlistand inputs inside it. Code above will find all inputs inside element with ID that ends withcheckboxlistand will be fired when one of those elements is clicked.But attribute ends with could be slow, so it could be better to do something like this:
checkboxlist.ClientIDwill return ID of wrapper element on client side.UPD:
According to your HTML, it looks like ClientID is not needed (as it looks like you are using .net 4 with
ClientIDModeenabled). In that case you can simply use:Demo