I have the following checkboxes:
<input type='checkbox' value='1' class='unique group1'>
<input type='checkbox' value='2' class='unique group1'>
<input type='checkbox' value='1' class='unique group2'>
<input type='checkbox' value='2' class='unique group2'>
I need to allow only one checkbox to be selected (as radio button) or also no checkbox to be selected.
I was trying the following JQuery code:
$('input.unique').click(function() {
$unique.removeAttr('checked');
$(this).prop('checked', true);
});
But this treats all check boxes as being the same group but I have two groups.
How can I solve this?
UPDATE
If it makes it easy I could use only one class and data-group:
<input type='checkbox' value='1' class='unique' data-group='group1'>
<input type='checkbox' value='2' class='unique' data-group='group1'>
<input type='checkbox' value='1' class='unique' data-group='group2'>
<input type='checkbox' value='2' class='unique' data-group='group2'>
The reason I am not using name to select the groups is because this is being rendered by server side code and all names are different ...
So basically I need to find all checkboxes with class="unique" and then allow only none or one checkbox to be selected in each group, given by data-group.