In Limesurvey version 2.72.6, which question type would be best to allow a participant to choose up to 3 answers per column, while rows randomize on each page load?
We have tested several scenarios of question types (array by column, multiple choice, side-by-side, partial randomization) w/ combining JavaScript. We speculate that array (numbers) with checkbox layout selected is the proper question type, however we need some help making this possible.
I have attached a screenshot of an example and we just need to limit the number of entries per column. We are manipulating the following script but are open to all suggestions and/or different scripts. Can you please lead us in a more appropriate direction with the script and/or question type?
Goes into template:
Code:
//Define column and limit for each
var checkboxConfig = [
{name: col1, limit: 3},
{name: col2, limit: 3},
{name: col3, limit: 3},
{name: col4, limit: 3}
];
//Set variable for array as a whole
for (i = 0; i < checkboxConfig.length; i += 1) {
setLimit(checkboxConfig[i].name, checkboxConfig[i].limit);
}
//Assign Click Handler for each checkbox
function setLimit(name, limit) {
var els = document.getElementsByName(name);
for (i = 0; i<els.length; i += 1) {
els[i].onclick = checkboxClickHandler(els[i], limit);
}
}
//New function for each click handler
function checkboxClickHandler(el, limit) {
return function () {
limit_checkbox(el, limit);
}
}
//Limit checkbox function
function limit_checkbox(el, max) {
var count = 0,
i;
var checkboxes = document.getElementsByName(el.name);
for (i = 0; i < checkboxes.length; i += 1) {
if (checkboxes[i].checked) {
count = count + 1;
}
}
if (count > max) {
alert('Please select only ' + max + ' checkboxes.\
To select this option unselect one of the others.');
el.checked = false;
}
}
Goes into questions source:
Code:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
limit_checkbox(‘{el}’,[‘col1’,’ col2’,’ col3’,’ col4’])
});
var col1 = {688526X267X7389SQ001_SQ001,688526X267X7389SQ002_SQ001,688526X267X7389SQ003_SQ001,688526X267X7389SQ004_SQ001};
var col2 = {688526X267X7389SQ001_SQ002,688526X267X7389SQ002_SQ002,688526X267X7389SQ003_SQ002,688526X267X7389SQ004_SQ002};
var col3 = {688526X267X7389SQ001_SQ003,688526X267X7389SQ002_SQ003,688526X267X7389SQ003_SQ003,688526X267X7389SQ004_SQ003};
var col4 = {688526X267X7389SQ001_SQ004,688526X267X7389SQ002_SQ004,688526X267X7389SQ003_SQ004,688526X267X7389SQ004_SQ004}; </script>