mardi 17 novembre 2015

checkbox validation like I Agree to the Terms and Condition jquery

function toggleDisabled(target) {
  var confirm = $("input:checkbox:checked");
  if (!confirm.length > 0) {
    $("#confirm").addClass('disabled');
  } else {
    $("#confirm").removeClass('disabled');
  }
}

var $notnull = $('.notnull');

$(document).on('keyup change', '.notnull', function(e) {
  console.log(e.currentTarget)
  toggleDisabled(e.currentTarget);

});

$notnull.each(function(i, el) {
  toggleDisabled(el);
});

function reload() {
  $notnull.each(function(i, el) {
    toggleDisabled(el);
  });
}

function toggleDisabledNavButton(target) {
  var $target = $(target);

  var basic = $target.find('input').hasClass('disabled');
  if (basic) {
    $("#add").addClass('disabled');
  } else {
    $("#add").removeClass('disabled');
  }

}
var detailscontainer = $('.notnull');

$(document).on('keyup change click', 'input.notnull', function(e) {
  e.preventDefault();
  toggleDisabledNavButton($(e.currentTarget).closest('.info'));



});

detailscontainer.each(function(i, el) {
  toggleDisabledNavButton(el.closest('.info'));
});
.disabled {
  border-color: red;
  background: gray;
  //pointer-events: none;

}
input[type=checkbox].disabled {
  outline: 2px solid red;
}
<script src="http://ift.tt/1qRgvOJ"></script>

<div class='info'>
  <input type="checkbox" name="" class="notnull disabled" id="confirm">
  <label for="confirm">Confirm</label>
  <input type="button" name="" value="Add" class="notnull disabled" id="add">
</div>

I want to create a Validation like I Agree to the Terms and Condition I made several function to run the script. When I added the code to check if the the checkbox has no class disabled the checkbox does not get checked anymore. I want to make this code work because i want to add more checkbox in the validation like Legal age etc. I cant find what i did wrong and i cant pinpoint why the checkbox does not get checked anymore.

Question:

  1. Why is my checkbox does not get checked.



Aucun commentaire:

Enregistrer un commentaire