I have a problem that I have been looking for an answer for a while and cannot make it work.
I am looking for a way to check if at least one checkbox is checked in the checkbox group. It is so complicated for me that each of these inputs has different name meanings. I found answers only for jQuery validation plugin etc. Here is my html:
<tr class="formField-checkbox formFieldRequired">
<td class="formLabelHolder"><label for="field129">Group of checkboxes</label></td>
<td class="formFieldHolder">
<input type="checkbox" name="field129[0]" class="formCheckbox required" value="Something1">
<label><span class="formCheckboxLabel">Something1</span></label>
<input type="checkbox" name="field129[1]" class="formCheckbox required" value="Something2">
<label><span class="formCheckboxLabel">Something2</span></label>
<input type="checkbox" name="field129[2]" class="formCheckbox required" value="Something3">
<label><span class="formCheckboxLabel">Something3</span></label>
</td>
</tr>
Here is my jQuery that I have now:
var named = [];
var $requiredCheck = $(this).find('input[type="checkbox"].required');
$($requiredCheck,$formId).each(function() {
named[$(this).attr('name')] = true;
});
for (name in named) {
var $checkboxes = $("input[name='" + name + "']");
if ($checkboxes.filter(':checked').length == 0) {
$checkboxes.closest('.formFieldHolder').addClass('error').append('<span class="error">Required!</span>');
}
}
, . append , . , , , . , . - html. , , - [0], [1] [2] , , .
, jQuery , , . name= "130 [0]", name= "130 [1]" name= "130 [2]". , , , .
.
EDIT:
,