Hi all,
I need to make a function, that returns the number of checkbox groups that has any values marked.
So im not after the checkbox alone, nor their values - Lets say I have 4 groups on the page - I need to know how many groups the user has marked.
<input type="checkbox" name="groupOne" value="17" />
<input type="checkbox" name="groupOne" value="16" />
<input type="checkbox" name="groupTwo" value="acer" />
<input type="checkbox" name="groupTwo" value="dell" />
<input type="checkbox" name="groupThree" value="intel" />
<input type="checkbox" name="groupThree" value="amd" />
<input type="checkbox" name="groupFour" value="windows" />
<input type="checkbox" name="groupFour" value="mac" />
I have this, which is not dynamic - And im sure their is a smarter way - Maybe using .map (jquery), in some way?
$( '.cb' ).click( function( e )
{
var totalCheckedGroups = 0;
if( $( "input[name='groupOne[]']" ).is(':checked') && $( "input[name='groupTwo[]']" ).is(':checked') )
{
totalCheckedGroups = 2;
console.log( totalCheckedGroups );
}
else if( $( "input[name='groupOne[]']" ).is(':checked') || $( "input[name='groupTwo[]']" ).is(':checked') )
{
totalCheckedGroups = 1;
console.log( totalCheckedGroups );
}
});
The more groups I need to check for, im getting too many scenarious to check for.
Anyone knows of a way to dynamically retreive the amount of groups holding anything from 1-xx values in JQuerian?
Best, Klemme