Okay, then place the following script in the source of the array.
Code:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
// Identify this question
var thisQuestion = $('#question{QID}')
// Add some classes to the answer cells
$('td.question-item', thisQuestion).addClass('normal-opt');
$('tr.subquestions-list', thisQuestion).each(function(i) {
$('.normal-opt:last', this).removeClass('normal-opt').addClass('exlusive-opt')
});
// Insert the checkboxes
$('.exlusive-opt input[type="text"]', thisQuestion).hide();
$('.exlusive-opt', thisQuestion).append('<input type="checkbox" class="checkbox">');
// A listener on the text inputs
$('.normal-opt input[type="text"]', thisQuestion).on('keyup change paste', function() {
var thisInput = $(this);
var thisRow = $(this).closest('tr.subquestions-list');
setTimeout(function() {
if(thisInput.val() != ''){
$('.exlusive-opt input[type=checkbox]', thisRow).prop('checked', false);
$('.exlusive-opt input[type=text]', thisRow).val('');
}
}, 100);
});
// A listener on the checkboxes
$('.exlusive-opt input[type="checkbox"]', thisQuestion).change(function(event) {
var thisCell = $(this).closest('td.question-item');
var thisRow = $(this).closest('tr.subquestions-list');
if($(this).is(':checked')) {
$('input[type=text]', thisCell).val(1);
$('.normal-opt input[type=text]', thisRow).val('');
}
else {
$('input[type=text]', thisCell).val('');
}
});
// Initial states
$('.exlusive-opt input[type="text"]', thisQuestion).each(function(i) {
var thisCell = $(this).closest('td.question-item');
if($(this).val() != '') {
$('input[type=checkbox]', thisCell).prop('checked', true);
}
});
});
</script>