Placing this script in the source of an array-numbers-checkboxes question will enforce a maximum of 3 items checked per row.
Code:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
// Define the maximum answers per row
var maxAnswers = 3;
// Identify this question
var thisQuestion = $('#question{QID}');
// Listener on the checkboxes
$('input[type="checkbox"]', thisQuestion).on('change', function(e) {
var thisRow = $(this).closest('tr');
$('input[type="checkbox"]', thisRow).prop('disabled', false);
// If max reached, disable unchecked inputs in this row
if($('input[type="checkbox"]:checked', thisRow).length >= maxAnswers) {
$('input[type="checkbox"]:not(:checked)', thisRow).prop('disabled', true);
}
});
});
</script>
That you can do easily by the built-in option of question validation (count(self.sq_SQ001_X)<4) and (count(self.sq_SQ002_X)<4) and (count(self.sq_SQ003_X)<4) and (count(self.sq_SQ004_X)<4)
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Yes, I know.
As you see in the validation there is the check row by row.
Only if there are more than 3 mentions in one row the error message will appear.
But I admit that it is a bit confusing that the whole question is marked as "wrong" in case there are 4 mentions in one row.
On the other side you get the message immediately after your wrong entry.
Joffm
You see, I prefer built-in features. Too many times a workaround didn't work anymore after an update or a new major release and had to be adapted.
Volunteers are not paid.
Not because they are worthless, but because they are priceless