I've seen several posts similar to what I'm looking for, but not quite my exact circumstance. I want to show/hide html divs when some check boxes are clicked.
I've found the following:
<script>
jQuery(function(){
var checks = $('#checkbox1, #checkbox2, #checkbox3');
checks.click(function(){
if (checks.filter(':checked').length == checks.length) {
$('#purchaseForm').show();
} else {
$('#purchaseForm').hide();
}
}).triggerHandler('click')
})
</script>
<label><input name="checkbox1" id="checkbox1" value="" type="checkbox"> checkbox1 </label>
<label><input name="checkbox2" id="checkbox2" value="" type="checkbox"> checkbox2 </label>
<label><input name="checkbox3" id="checkbox3" value="" type="checkbox"> checkbox3 </label>
<div id="purchaseForm">
Content Here
</div>
What I'm looking for is:
<label><input name="checkbox1" id="checkbox1" value="" type="checkbox"> checkbox1 </label>
<label><input name="checkbox2" id="checkbox2" value="" type="checkbox"> checkbox2 </label>
<label><input name="checkbox3" id="checkbox3" value="" type="checkbox"> checkbox3 </label>
<div id="A">
Display for selected Checkbox one only
</div>
<div id="B">
Display for selected Checkbox two only
</div>
<div id="C">
Display for selected Checkbox three only
</div>
<div id="D">
Display for selected Checkboxes one and two
</div>
<div id="E">
Display for selected Checkboxes one and three
</div>
<div id="F">
Display for selected Checkboxes two and three
</div>
<div id="G">
Display for selected Checkboxes one two and three
</div>
This helped me understand this a little bit more, but not everything. When all three checkboxes are clicked, the content appears. What I'm looking for is content based on the combinations of check boxes.
For example, say checkbox1 is selected, then only div-A would display. But if checkboxes 1 and 3 are both selected, then div-E would display, and I'm looking for that with each checkbox.
I'm still learning javascript so any advice would be greatly appreciated. Thanks!
var chk = document.getElementById ('checkbox1').checkedwhich will be true or falsevar chk = $('input[type=checkbox]).prop('checked')it will be true or false (getter) andvar chk = $('input[type=checkbox]).prop('checked', true)it will check the checkboxes (setter)