Reputation: 185
I have this Fiddle and i made the script to work when the check box is checked first and than text inserted in input,but if i try to insert text first button wont enable it self. Can someone look at that fiddle? this is my script
$('.checkset label').on('change', function () {
var reqlength = $('.important').length;
console.log(reqlength);
var value = $('.important').filter(function () {
return this.value != '';
});
if ($('.checkset label').hasClass("checked")) {
if (value.length >= 0 && (value.length !== reqlength)) {
//alert('Please fill out all required fields.');
$('#reg').prop('disabled', true);
$('#reg').addClass('inactive');
} else {
//alert('Everything has a value.');
$('#reg').prop('disabled', false);
$('#reg').removeClass('inactive');
}
} else {
$('#reg').prop('disabled', true);
$('#reg').addClass('inactive');
}
});
$(".important").on('change', function () {
$('.checkset label').change();
});
Upvotes: 4
Views: 483
Reputation: 1
Try substituting input
element for label
element at change
events , utilizing .toggleClass()
to set .checked
class at on .checkset label
if all .important
input
elements have, do not value
$(".checkset").click(function(){
$(this).find("label").toggleClass("checked");
});
var res;
var inputs = $(".important, .checkset input");
inputs.on("input change", function() {
res = inputs.get().every(function(el) {
return $(el).is("[type=checkbox]") ? el.checked : el.value.length !== 0
});
$("#reg").prop("disabled", !res)
.toggleClass("inactive", !res)
})
jsfiddle http://jsfiddle.net/r9rsddhk/15/
Upvotes: 1