vendredi 5 janvier 2018

Disable/enable next checkbox based on previous checkbox selection - jQuery

I want to disable the next checkbox if I select the previous one, it doesn't matter which one is selected only next should disable when previous checkbox is clicked but unfortunately can't get it working

Following is the code:

$(function() {
  var next = $(".checkboxes").next().find(":checkbox");
  //alert(next);
  $('.checkboxes input[type=checkbox]').bind("click", function() {
    if ($(this).is(':checked')) {
      $(this).next().prop("disabled", true);
    } else {
      $(this).next().prop("disabled", false);
    }
  });
});
.checkboxes {
  float: left;
  width: 100%;
  margin-bottom: 10px;
}
<script src="http://ift.tt/1qRgvOJ"></script>
<label class="checkboxes"><input type="checkbox" name="radiocheck-checkDefault__Group" id="check1">Option1</label>
<label class="checkboxes"><input type="checkbox" name="radiocheck-checkDefault__Group" id="check2">Option2</label>
<label class="checkboxes"><input type="checkbox" name="radiocheck-checkDefault__Group" id="check3">Option3</label>
<label class="checkboxes"><input type="checkbox" name="radiocheck-checkDefault__Group" id="check4">Option4</label>
<label class="checkboxes"><input type="checkbox" name="radiocheck-checkDefault__Group" id="check5">Option6</label>
<label class="checkboxes"><input type="checkbox" name="radiocheck-checkDefault__Group" id="check6">Option6</label>



Aucun commentaire:

Enregistrer un commentaire