1) Place something like this in the source of the second array. It will render a hidden array of all answered Q1 sub-question codes that we can access with JavaScript.
Code:
<div class="hidden equation">
{implode(',', if(D1_D1Y1_D1X1 == '1', 'D1Y1_D1X1', ''), if(D1_D1Y1_D1X2 == '1', 'D1Y1_D1X2', ''), if(D1_D1Y1_D1X3 == '1', 'D1Y1_D1X3', ''), if(D1_D1Y2_D1X1 == '1', 'D1Y2_D1X1', ''), if(D1_D1Y2_D1X2 == '1', 'D1Y2_D1X2', ''), if(D1_D1Y2_D1X3 == '1', 'D1Y2_D1X3', ''), if(D1_D1Y3_D1X1 == '1', 'D1Y3_D1X1', ''), if(D1_D1Y3_D1X2 == '1', 'D1Y3_D1X2', ''), if(D1_D1Y3_D1X3 == '1', 'D1Y3_D1X3', ''), if(D1_D1Y4_D1X1 == '1', 'D1Y4_D1X1', ''), if(D1_D1Y4_D1X2 == '1', 'D1Y4_D1X2', ''), if(D1_D1Y4_D1X3 == '1', 'D1Y4_D1X3', ''))}
</div>
2) Add this script to the source of Q2. It will loop through that hidden array and disable Q2 sub-questions if the corresponding Q1 sub-question was not answered.
Code:
<script type="text/javascript" charset="utf-8">
$(document).on('ready pjax:scriptcomplete',function(){
var q1Code = 'D1';
var q2Code = 'D2';
var answeredQ1 = $.trim($('#question{QID} .hidden.equation:eq(0)').text()).split(',');
// Loop through answers from Q1 and add classes to the corresponding Q2 inputs
$.each(answeredQ1, function(i, val) {
var re = new RegExp(q1Code, 'g');
var q2CellCode = val.replace(re, q2Code);
if(val != '') {
$('#question{QID} input[type="text"][id$="'+q2CellCode+'"]').addClass('relevant');
}
});
// Disable irrelevant items
$('#question{QID} input[type="text"]:not(.relevant)').prop('disabled', true).val('');
});
</script>