mardi 19 avril 2016

Multiple checkboxes opening toggle divs each one. Only one can be selected at the same time

I have multiple checkboxes customized by css. With the function only one can be selected at the same time, like radios. I use toggle in onchange event to affect all changes in checkboxes.

    <input type="checkbox" name="plus" onchange="toggleByClass('masinfo1');" class="plusultra" id="checkmas1" value=""><label for="checkmas1"><span></span></label>
<input type="checkbox" name="plus" onchange="toggleByClass('masinfo2');" class="plusultra" id="checkmas2" value=""><label for="checkmas2"><span></span></label>
<input type="checkbox" name="plus" onchange="toggleByClass('masinfo3');" class="plusultra" id="checkmas3" value=""><label for="checkmas3"><span></span></label>








    `$`( document ).ready(function() {
 `$`(function() {
    $("input:checkbox").on('click', function() {
      var $box = $(this);
      if ($box.is(":checked")) {
        var group = "input:checkbox[name='" + $box.attr("name") + "']";
           $(group).prop("checked", false);
        $box.prop("checked", true);
      } else {
        $box.prop("checked", false);
      }
    });
  });

});

The problem is onchage dont close the div when I click another checkbox, and I dont underestand why. Can anybody help me? THX so much! Sorry guys Its my first post and my english its not the best.




Aucun commentaire:

Enregistrer un commentaire