I have a form with some radio buttons and checkboxes. Some checkboxes/radio have some hidden dividers next to them. The hidden dividers should only become visible when a user select the corresponding radio/checkbox.
Each radio/checkbox has a value in this format 123:456
the corresponding hidden divider will have an id
attribute equal to group_123_456
I am able to find the divider id's value that I needs to visible/hide from the value of each item (checkbox or radio.)
I thought I can get a way by utilizing the change()
event. I thought I can evaluate each item. If the item is check, show the corresponding div otherwise hide it.
Here is what I have done
$("input[type='radio'], input[type='checkbox']").change(function(e) {
$(this).each(function(index, item){
var newGroupName = '';
if( $(item).is(':checked') ){
console.log( $(item).val() + ' is checked' );
newGroupName = getGroupElement( $(this).val() );
$('#' + newGroupName).show();
} else {
console.log( $(item).val() + ' is NOT checked' );
newGroupName = getGroupElement( $(this).val() );
$('#' + newGroupName).hide();
}
});
}).change();
The above code works for the checkboxes but it does not work for the radio buttons.
I create a fiddle to give you a good idea of what I am trying to do here https://jsfiddle.net/oke8qLwg/2/
How can I show/hide the correct divider everytime the use change the input's value?