Combining checkbox selectors for unique results in jQuery
I have 3 checkboxes, and I want all combinations (about 8 or 9) of those checkboxes to display a different result, but I cannot work out how to do so. It feels like there's a simple way of doing this that I'm missing.
Here's the Frankenstein monster-code I have so far, which doesn't do what I'd like it to. The aim is that the following code sees that a user has has checked both the "webcam" (#checkWebcam) and "chat" (#checkChat) boxes, and that a different download link is being displayed based on that selection combo...
- jQuery('#checkWebcam, #checkChat, #checkSocial').change(function() {
- var nowcnos = jQuery('#checkChat');
- var nowcnoschecked = nowcnos.filter(':checked'); //Filter checked checkboxes
- var nocnos = jQuery('#checkWebcam');
- var nocnoschecked = nocnos.filter(':checked'); //Filter checked checkboxes
- if(nowcnos.length == nowcnoschecked.length){ //if length are same
- jQuery('div.strip.download').html('<a href="<?php echo $noc; ?>" class="btn btn-lg btn-to gradient-to">Download</a>');
- } else if {(nocnos.length == nocnoschecked.length){ //if length are same
- jQuery('div.strip.download').html('<a href="<?php echo $noc; ?>" class="btn btn-lg btn-to gradient-to">Download</a>');
- } else {
- jQuery('div.strip.download').html('<a href="<?php echo $download; ?>" class="btn btn-lg btn-to gradient-to">Download</a>');
- }
- });
Is there some way of doing this in jQuery or Javascript? So far I've only found solutions that kind of give yes/no answers, and not ones that consider the multiple different outcomes of the checkbox selections.