Find all checkboxes with the same name, then ensure one radio is selected
Hi all. I have a range of radio buttons in a form. I need to have jQuery check that a radio is selected for each group and add a class to the label associated if not.
I thought this would work, but am having issues. I have checked and the name of the group is correctly added to the variable 'radio'. Any ideas?
- $('.checkbox', this).each(function(){
var radio = $(this).attr("name");
if ($('input[name='+ radio +']:checked').length) {
$('label[for=' + radio + ']').addClass('error_label');
required = false;
} else {
$('label[for=' + radio + ']').removeClass('error_label');
}
});