At the moment I'm working on a small jQuery element. I have 2 main checkboxes: ja and nee. When one of the boxes is checked, a submenu opens up and the checkboxes in the submenu are filled in according to which main checkbox you check (ja or nee). This works fine.
In the submenu the user can choose ja or nee with the set of check boxes that were populated with the initial click. The problem I'm having, is that when the user first checks the main checkbox to "nee" and then changes the checkboxes in the submenu to "ja", the main checkbox stays at "nee".
So I'm thinking I could fix this with a if/else statement but I can't figure out how to do it. I made it so that all the checkboxes have a state "checked" or no state when not checked, they also have classes ("ja" and "no").
This is the jQuery code I'm using now
$('.open_sub_ja').click(function () {
$(this).parents('.container_vragen').find('.ja').attr('checked', this.checked);
$(this).parents('.container_vragen').find('.nee').removeAttr('checked');
});
$('.open_sub_nee').click(function () {
$(this).parents('.container_vragen').find('.ja').removeAttr('checked');
$(this).parents('.container_vragen').find('.nee').attr('checked', this.checked);
});
$('.ja').click(function () {
$(this).parents('.antwoorden').find('.ja').attr('checked', this.checked);
$(this).parents('.antwoorden').find('.nee').removeAttr('checked');
});
$('.nee').click(function () {
$(this).parents('.antwoorden').find('.ja').removeAttr('checked');
$(this).parents('.antwoorden').find('.nee').attr('checked', this.checked);
});
A small jsFiddle can be found here http://jsfiddle.net/Macjm/. Any help is well helpfull for I have very little knowledge on the if/else statement.