My HTML form contains many checkbox groups,I want to check if atleast one checkbox is selected from every group.
For example
// Group vehicle
<input type="checkbox" name="vehicle" value="Bike"/> I have a bike<br />
<input type="checkbox" name="vehicle" value="Car"/> I have a car <br/>
// Group language
<input type="checkbox" name="language" value="JS"/> I am JS Ninja <br/>
<input type="checkbox" name="language" value="Android"/> I am a droid <br/>
I can use following Jquery selector to check if at least one checkbox is selected
if($(":checkbox:checked[vehicle]").length) > 1
if($(":checkbox:checked[language]").length) > 1
But I have to repeat this selector for every checkbox group. My page contains many checkbox groups. Is there any other way by which I can select all checkbox groups in single jquery selector?
Thanks!
Updated as promised, once I had the time to fully test the original example code. I see you guys went a little overboard, it only needed some minor adjustments to function 😀
I also made it a bit more efficient by not repeating the jQuery checkbox selectors multiple times.
And the result: