0

I'm struggling with this for a week now and I can't find an answer. I have a multiple checkbox in a Sharepoint form:

R1 R2 R3 R4 R5 R6

I need to know when two or more checkboxes are checked. In order to achieve this I think that the best way is to store the value of the selected checkboxes as a string and check the length of that string, but I can't find a way to do it.

Can you please help?

<span class="spForm" id="check" data-displayname="Region">
   <!-- FieldName="Region"
      FieldInternalName="Region"
      FieldType="SPFieldMultiChoice"
      -->
   <span dir="none">
      <table id="Region_b10381e0-f898-4564-8bb9-1f5151ae277d_MultiChoiceTable" cellspacing="1" cellpadding="0">
         <tbody>
            <tr>
               <td><span class="ms-RadioText" title="R1"><input id="Region_b10381e0-f898-4564-8bb9-1f5151ae277d_MultiChoiceOption_0" type="checkbox"><label for="Region_b10381e0-f898-4564-8bb9-1f5151ae277d_MultiChoiceOption_0">R1</label></span></td>
            </tr>
            <tr>
               <td><span class="ms-RadioText" title="R2"><input id="Region_b10381e0-f898-4564-8bb9-1f5151ae277d_MultiChoiceOption_1" type="checkbox"><label for="Region_b10381e0-f898-4564-8bb9-1f5151ae277d_MultiChoiceOption_1">R2</label></span></td>
            </tr>
            <tr>
               <td><span class="ms-RadioText" title="R3"><input id="Region_b10381e0-f898-4564-8bb9-1f5151ae277d_MultiChoiceOption_2" type="checkbox"><label for="Region_b10381e0-f898-4564-8bb9-1f5151ae277d_MultiChoiceOption_2">R3</label></span></td>
            </tr>
            <tr>
               <td><span class="ms-RadioText" title="R4"><input id="Region_b10381e0-f898-4564-8bb9-1f5151ae277d_MultiChoiceOption_3" type="checkbox"><label for="Region_b10381e0-f898-4564-8bb9-1f5151ae277d_MultiChoiceOption_3">R4</label></span></td>
            </tr>
            <tr>
               <td><span class="ms-RadioText" title="R5"><input id="Region_b10381e0-f898-4564-8bb9-1f5151ae277d_MultiChoiceOption_4" type="checkbox"><label for="Region_b10381e0-f898-4564-8bb9-1f5151ae277d_MultiChoiceOption_4">R5</label></span></td>
            </tr>
            <tr>
               <td><span class="ms-RadioText" title="R6"><input id="Region_b10381e0-f898-4564-8bb9-1f5151ae277d_MultiChoiceOption_5" type="checkbox"><label for="Region_b10381e0-f898-4564-8bb9-1f5151ae277d_MultiChoiceOption_5">R6</label></span></td>
            </tr>
            <tr>
               <td><span class="ms-RadioText" title="R0"><input id="Region_b10381e0-f898-4564-8bb9-1f5151ae277d_MultiChoiceOption_6" type="checkbox"><label for="Region_b10381e0-f898-4564-8bb9-1f5151ae277d_MultiChoiceOption_6">R0</label></span></td>
            </tr>
         </tbody>
      </table>
   </span>
</span>
1

Refer below code this will give you the count of all checked checkboxes.

$("#check").find("input[type='checkbox']:checked").length;

Also In you Case If you want to know which checkboxes are checked (which span contains the checked checkbox) you can refer blow code. This will give you title of all spans that contains the checked checkbox:

$("#check").find("input[type='checkbox']:checked").each(function(){
    alert($(this).closest('span').attr("title"));
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.