So here is what my form looks like.
and the JS I tried:
$('#work_direction').on('click' , function() {
$('.cad, .design, .shop, .cnc').on('click', function(){
$classname = $(this).attr('class');
if($('.' + $classname + ":checked").length > 0){
$('#' + $classname).attr('checked','checked');
} else {
$('#' + $classname).removeAttr('checked');
}
});
});
Theres some functionality there and it works as far as I know. However, I want to make it so that when "Mexico" is chosen in Direction, when user checks off S - SHOP or M - CNC, it shouldn't check off these two in Departments Affected
- Shop (John Doe [3])
- CNC (John Doe [4])
but instead it should check off
- Mexico (John Doe [7])
The form should work the way it does for both Domestic and Offshore, in that when the bottom C, D, S, M get checked off then the top CAD, Design, Shop, CNC, get checked off. The functionality changes like described above when user chooses "Mexico" as direction.
Here is the code I tried, Check and uncheck checkbox not working correctly but I had issues described in beautifulcoder's comment: "Basically, I think you are running into issues with event bubbling. If you use live(), jQuery will add the event now and in the future. The next time you add an event it gets appended to the list."
I'm not sure how to implement a fix or whether there is a better approach.