I have a group of php generated checkboxes :
<?php foreach($checkbox as $check) {?>
<input type = "checkbox" name="checkbox[]" class="<?php echo $check -> class ?>" value ="<?php echo $check -> value ?>" /><?php echo $check->value ?>
<?php } ?>
Above PHP generates HTML below:
<input type="checkbox" name="checkbox[]" class="class1" value="Checkbox1" />Checkbox1
<input type="checkbox" name="checkbox[]" class="class1" value="Checkbox2" />Checkbox2
<input type="checkbox" name="checkbox[]" class="class1" value="Checkbox3" />Checkbox3
<input type="checkbox" name="checkbox[]" class="class2" value="Checkbox4" />Checkbox4
<input type="checkbox" name="checkbox[]" class="class2" value="Checkbox5" />Checkbox5
<input type="checkbox" name="checkbox[]" class="class2" value="Checkbox6" />Checkbox6
<input type="checkbox" name="checkbox[]" class="class3" value="Checkbox7" />Checkbox7
<input type="checkbox" name="checkbox[]" class="class3" value="Checkbox8" />Checkbox8
To explain above, I have three classes of checkboxes, and would like that:
If I check any in class1, class3 becomes disabled, if I uncheck, class3 is back enabled.
If I check class2 , all of the other class2 become disabled, class1 remains checked if already checked, becomes checked if not.
I have tried doing this, using the Script below.
$('input[class*="class"]').click(function(){
if($(this).is(':checked')){
var classValue = $(this).attr('class');
if(classValue == 'class1'){
$('.class3').prop('disabled', true);
$('.class3').prop('checked', false);
}
else if(classValue == 'class2'){
$('.class2').not(':checked').prop('disabled', true);
$('.class3').prop('disabled', true);
}
else if(classValue == 'class3'){
$('.class1').prop('checked', false);
$('.class2').prop('checked', false);
$('.class1, .class2').prop('disabled', true);
}
}
})
Doesn't work though.
class3, but your code has this case in it. Which is it?