Within my application, there is a checkbox list. The following HTML code showcases the structure of the checkbox list along with the VB code responsible for binding it upon loading the respective page.
<asp:CheckBoxList Runat="server" id="chklistTeams" RepeatColumns="7" RepeatDirection="Horizontal"
CellPadding="4" Font-Size="7pt"></asp:CheckBoxList>
Below is the VB code used to bind the checkbox list:
myCmd.CommandText = "Select id, title from teams"
Dim DS As SqlDataReader
DS = myCmd.ExecuteReader
chklistTeams.DataValueField = "id"
chklistTeams.DataTextField = "title"
chklistTeams.DataSource = DS
chklistTeams.DataBind()
DS.Close()
Upon clicking the save button, a JavaScript function is triggered. Here is a snippet of that function which aims to retrieve the values of the items:
var checkList = document.getElementById('chklistTeams');
var checkBoxList = checkList.getElementsByTagName("input");
var checkBoxSelectedItems = new Array();
for (var i = 0; i < checkBoxList.length; i++) {
if (checkBoxList[i].checked) {
checkBoxSelectedItems.push(checkBoxList[i].value);
alert('checked - checkBoxList[i]: ' + checkBoxList[i].value)
}
}
Despite storing values in the array, all retrieved values show as "on" upon testing (as confirmed by the alert). Upon inspecting the HTML of the checkboxes, one entry appears as follows:
<input name="chklistTeams:21" id="chklistTeams_21" type="checkbox" value="on"/>
The previous VB code accurately fetched integer values for checked items. However, our current requirement mandates fetching these values via JavaScript due to restrictions on using PageMethods with a public shared function on the backend.
Kindly advise on why the JavaScript method returns "on" instead of the integer values like the VB approach. Appreciate any assistance provided. Remember, JS must be used, and the VB method cannot be utilized due to its public shared nature. Thank you.