Hi Ben.
I would be inclined to insert a hidden copy of Q2 (call it
qHidden) after Q1 and then use JavaScript to toggle the check-boxes in the hidden question. Corresponding food "group" sub-questions can be identified by the first 4 characters of sub-question codes.
Then you could filter Q2 by qHidden, allowing you to place it anywhere in the survey and make it mandatory (if necessary).
After adding that copy, place the following script placed in the source of Q1. I think the comments explain it but please ask if you are confused about any of it.
Code:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
// Identify the questions and IDs
var q1ID = {QID};
var q1 = $('#question'+q1ID);
var qHidden = q1.nextAll('.multiple-opt:eq(0)');
var qHiddenID = qHidden.attr('id').replace(/question/, '');
// Hide qHidden
qHidden.hide();
// Listeners on the Q1 checkboxes
$('input.checkbox', q1).change(function(e) {
var q1Checkbox = $(this);
// Define the food "group"
var foodGroup = $(this).attr('id').split('X'+q1ID)[1].substr(0, 4);
// Loop through subquestions within the food "group" in qHidden
$('input.checkbox[id*="X'+qHiddenID+foodGroup+'"]', qHidden).each(function(i) {
// Toggle the checkbox(es) in qHidden
$(this).prop('checked', $(q1Checkbox).prop('checked'));
$(this).nextAll('input[type="hidden"]:eq(0)').attr('value', $(q1Checkbox).nextAll('input[type="hidden"]:eq(0)').attr('value'));
// Fire the Expression Manager checkconditions() function
checkconditions(this.value, this.name, this.type);
});
});
});
</script>