1

please let me know what I can correct here, I'm locked in on something seemingly simple.

Using JQuery 1.6.2:

I am trying to return an array of VALUES of checked items in CheckBoxList.

Using modified examples from web I have the following, which returns an array of "on, on, on, on" (if all 4 checkboxes checked).

Shots.push($(this).prop('checked')) returns "true, true..." Shots.push($(this).attr('Value')) returns "on, on..."

            var Shots = [];

            $('#cblShots').find('input[type=checkbox]:checked').each(function () {
                Shots.push($(this).val());
            });

                if (Shots != "") {
                    $(Pnote).val(Shots.join(', '));
                } else {
                    updateTips("Please select at least one item");
                    return false;
                }


<asp:Panel ID="pnlAppointmentShotSelection" runat="server" style="display:none;">
    <label>Please select which shots you would like administered</label>
    <br /><br />
    <asp:CheckBoxList ID="cblShots" runat="server" CssClass="ShotList">
      <asp:ListItem Value="Flu">Flu</asp:ListItem>
      <asp:ListItem Value="B-12">B-12</asp:ListItem>
      <asp:ListItem Value="Pneumonia">Pneumonia</asp:ListItem>
      <asp:ListItem Value="TDAP">Tetanus-Diptheria-Pertusis (TDAP)</asp:ListItem>
    </asp:CheckBoxList>
   </asp:Panel>
user1457613
  • 97
  • 1
  • 3
  • 12

1 Answers1

0

Acording this post is available add data-attributes to ListItem, so try add data-name attributes to each element and then, try this in javascript :

var Shots = [];
$('#cblShots').find('input[type=checkbox]:checked').each(function () {
      Shots.push($(this).attr("data-name"));
});
Community
  • 1
  • 1
Maxi Baez
  • 578
  • 5
  • 13