If I have groups of checkboxes like so:
<input type="checkbox" name"checkboxes1" value="#value1">
<input type="checkbox" name"checkboxes1" value="value2">
<input type="checkbox" name"checkboxes1" value="#value3">
<input type="checkbox" name"checkboxes2" value="value1">
<input type="checkbox" name"checkboxes2" value="#value2">
<input type="checkbox" name"checkboxes2" value="#value3">
Is there an easy way in jquery to return a value of 1 for each group of checkboxes, if both of the following conditions apply:
- All of the checkboxes in the group that start with a # in their value are checked
- All of the checkboxes in the group that don’t start with a # in their value are not checked
Note: the names of the checkboxes are dynamically generated, so there could be any number in a group, any number of groups and each group could have any name.
Thanks 🙂
You can select the attribute with [attr^=\#] pattern.
So, you could code something like:
EDIT
Updated Full working code. This is only checking checkboxes with class cb1, but just to give you an idea how to achieve. I must apologize that the original code has some problem that I didnt check it. Anyway, I try the above code and it should be fine (should you modify the jquery directory reference).