jeudi 13 septembre 2018

JavaScript: Limit checkbox checked for a specific Div id

I need your help to find out how to call an input type=checkbox under sibling divs then to unable checkbox is the click is greater than 2

This is code

$("#qwrap27491 :checkbox").click(function() {
  if ($("#qwrap27491 :checkbox:checked").length >= 3) {
    $("#qwrap27491 :checkbox:not(:checked)").attr("disabled", "disabled");
    Alert("Please choose only 2 cases");
  } else {
    $("#qwrap27491 :checkbox").attr("disabled", "");
  }
});
<div id="qwrap27491" class="Question">
  <div class="checkboxQuestion">
    <div class="checkboxleft">
      <div class="qNumber" style="display: none;">0.1.15</div><label for="q27491" title="q27491" style="max-width: 385px;">CheckList</label></div>
    <div class="checkboxGroup">
      <div class="button-holder"><label style="max-width: 385px;"><div class="checkboxitem"><input type="checkbox" id="q27491" name="q27491" value="1568"></div><div class="checkboxlabel">5</div></label></div>
      <div class="button-holder"><label style="max-width: 385px;"><div class="checkboxitem"><input type="checkbox" id="q27491" name="q27491" value="1567"></div><div class="checkboxlabel">4</div></label></div>
      <div class="button-holder"><label style="max-width: 385px;"><div class="checkboxitem"><input type="checkbox" id="q27491" name="q27491" value="1566"></div><div class="checkboxlabel">3</div></label></div>
      <div class="button-holder"><label style="max-width: 385px;"><div class="checkboxitem"><input type="checkbox" id="q27491" name="q27491" value="1565"></div><div class="checkboxlabel">2</div></label></div>
      <div class="button-holder"><label style="max-width: 385px;"><div class="checkboxitem"><input type="checkbox" id="q27491" name="q27491" value="1564"></div><div class="checkboxlabel">1</div></label></div>
    </div>
  </div>
</div>

PS: I cannot edit the HTML, this is why I m trying to find the solution via a script.

Thank you BKC




Aucun commentaire:

Enregistrer un commentaire