Return dynamic CheckBoxList span ID on button click

d4ftpuNK

New Member
I have a dynamic \[code\]CheckBoxList\[/code\] that creates an HTML table. I've listed one row to keep it simple.\[code\]<table id="checkBoxList1" border="0"> <tr> <td><span someValue="http://stackoverflow.com/questions/14074568/neededValue"><input id="checkBoxList1_0" type="checkbox" name="checkBoxList1$0" checked="checked" /><label for="checkBoxList1_0">TestTopic1</label></span></td> </tr></table>\[/code\]I also have an ASP button that will run javascript when clicked. I need the function to return the \[code\]"neededValue"\[/code\]. Here is the ASP button and the javascript function:\[code\]<asp:Button ID="btnSubscribe" runat="server" Text="Update Subscriptions" OnClientClick="return GetSelectedItem()"/><script type="text/javascript">function GetSelectedItem() { var CHK = document.getElementById("<%=checkBoxList1.ClientID%>"); var checkbox = CHK.getElementsByTagName("input"); var spans = CHK.getElementsByTagName("span"); for (var i = 0; i < checkbox.length; i++) { if (checkbox.checked) { alert("Selected = " + spans); } } return false;}</script>\[/code\]Right now it returns a null value.
 
Back
Top