Doxfeefsams
New Member
in my application I have a checkbox list. Listed below is the html for the checkbox list, as well as the vb code that bind it on load of the page it is located on.\[code\]<asp:CheckBoxList Runat="server" id="chklistTeams" RepeatColumns="7" RepeatDirection="Horizontal" CellPadding="4" Font-Size="7pt"></asp:CheckBoxList>\[/code\]Below is the VB to bind the checkboxlist\[code\]myCmd.CommandText = "Select id, title from teams"Dim DS As SqlDataReaderDS = myCmd.ExecuteReaderchklistTeams.DataValueField = "id"chklistTeams.DataTextField = "title"chklistTeams.DataSource = DSchklistTeams.DataBind()DS.Close()\[/code\]When a save button is hit a javascript function is called. Here is the part of the function that is called that should get us the value of the items.\[code\]var checkList = document.getElementById('chklistTeams');var checkBoxList = checkList.getElementsByTagName("input");var checkBoxSelectedItems = new Array();for (var i = 0; i < checkBoxList.length; i++) { if (checkBoxList.checked) { checkBoxSelectedItems.push(checkBoxList.value); alert('checked - checkBoxList: ' + checkBoxList.value) }}\[/code\]All the values getting stored to the array (tested with the alert) - are coming back with the value "on" - so I then checked the html of the checkboxes in this list, here was the result for one of the checkboxes\[code\]<input name="chklistTeams:21" id="chklistTeams_21" type="checkbox" value="http://stackoverflow.com/questions/14564932/on"/>\[/code\]I am sure the values are being binded correctly to the list - because in the old way of getting their values, you get the correct integer value for the item - listed below is that VB code that used to handle this (and returned a string of integers, depending on how many boxes were checked - did not return a list of the value "on"). I need to be able to get this via javascript for another modification we are making on this page where we must now save using PageMethods and can't use this on the back end with a public shared functionVB code that will get the right values of checked items in checkboxlist\[code\] For Each li In chklistTeams.Items If li.Selected = True Then strTeamList = strTeamList & li.Value & "," bolTeamSelected = True End If Next If bolTeamSelected = True Then strTeamList = strTeamList.Substring(0, strTeamList.Length - 1) End If\[/code\]Can anyone see why the javascript way to get the values is giving me "on" instead of the integer value like the VB way does? Thanks again for your help. Again - this must be done in JS - can't use the VB code behind way due to the function being public and shared. Thanks.