Hi,
since yesterday I found a new approach that avoids a lot of nested IFs.
In the following ALL subquestion codes are numerical (1,2,...)
A. Group GCalc (here we initialise the whole stuff)
1. As already said, in a (hidden) question of type "long text" (Pool) insert all 144 possible combinations in this form.
Order: field (4), grade (3), activity (4), semester (3)
001:1111
002:1112
...
088:3221
089:3222
...
143:4342
144:4343
2. In a question of type "multiple short text" (QSelect) with two subquestions enter this script to
- randomize the 20 names
- randomly select 20 profiles
Code:
<script type="text/javascript" charset="utf-8">
function shuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
// And swap it with the current element.
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
$(document).on('ready pjax:scriptcomplete',function(){
// Fill the array with 20 characters
var arr = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T"];
arr = shuffle(arr).join('');
$('#question{QID} input[type="text"]:eq(0)').val(arr);
// Fill the array, numbers from 1 to 144
var arr1 = ;
for (var i = 1; i < 145; i++) {
var x = i.toString().padStart(4,"0").slice(-3);
arr1.push(x);
}
arr1 = shuffle(arr1).slice(0, 20).join('');
$('#question{QID} input[type="text"]:eq(1)').val(arr1);
//$('#question{QID}').hide();
});
</script>
Hide this question with css-class "d-none"
3.
- Create a (hidden) question of type "multiple short text" (PComb) with two subquestions to temporarly store the selected profiles
- Create (hidden) questions of type "list(radio)" to store and retrieve the texts.
PName1 and PName2 with answer options "A: Leon Schmidt", "B: Lukas Müller",...; "T: Ali Yıldız" (You see the coding refers to the characters in the script)
PField1 and PField2 with the four answer options of Field of study, coded 1,2,3,4
PGrade1 and PGrade2 with the three answer options of Grade, coded 1,2,3
PActive1 and PActive2 with the four answer options of activities, coded 1,2,3,4
PSem1 and PSem2 with the three answer options of Semester, coded 1,2,3
4. Because QSelect is hidden by css there would be displayed the skeleton of a question.
Therefore you may show a question of type "text display" with a message like "The profiles are initialised"
With this script you hide the buttons and proceed after some seconds
Code:
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
// Verstecke den „Weiter“-Button
$('#ls-button-submit').hide();
$('#ls-button-previous').hide();
setTimeout(function () {
$('#ls-button-submit').trigger('click');
}, 3000); // 3 Seconds, Value in milliseconds
});
</script>
That's all to initialise nearly everything.
Now you create the ten groups with two questions in each group
5. Create a (hidden) question of type "equation" where you set the hidden list(radio) questions with ExpressionScript.
(The advantage is: We only use numbers, but show the text with the property ".shown")
a. eqSet1
We capture the first and the second character of QSelect_1 (names)
and search the combination that matches the first and second number in QSelect_2 (remember: these numbers are three digits long)
Code:
{PName1=substr(QSelect_1,0,1)}
{PComb_1=substr(Pool,strpos(Pool,join(substr(QSelect_2,0,3),':'))+4,4)}
{PName2=substr(QSelect_1,1,1)}
{PComb_2=substr(Pool,strpos(Pool,join(substr(QSelect_2,3,3),':'))+4,4)}
{PField1=substr(PComb_1,0,1)}
{PField2=substr(PComb_2,0,1)}
{PGrade1=substr(PComb_1,1,1)}
{PGrade2=substr(PComb_2,1,1)}
{PActive1=substr(PComb_1,2,1)}
{PActive2=substr(PComb_2,2,1)}
{PSem1=substr(PComb_1,3,1)}
{PSem2=substr(PComb_2,3,1)}
b. eqSet2
and in the second we only have to change the indices in "PName1, PName2" and "PComb_1, PComb_2"
Code:
{PName1=substr(QSelect_1,2,1)}
{PComb_1=substr(Pool,strpos(Pool,join(substr(QSelect_2,6,3),':'))+4,4)}
{PName2=substr(QSelect_1,3,1)}
{PComb_2=substr(Pool,strpos(Pool,join(substr(QSelect_2,9,3),':'))+4,4)}
{PField1=substr(PComb_1,0,1)}
{PField2=substr(PComb_2,0,1)}
{PGrade1=substr(PComb_1,1,1)}
{PGrade2=substr(PComb_2,1,1)}
{PActive1=substr(PComb_1,2,1)}
{PActive2=substr(PComb_2,2,1)}
{PSem1=substr(PComb_1,3,1)}
{PSem2=substr(PComb_2,3,1)}
6. The second question in each group is your question.
This is a question of type "array" with one subquestion and two answer options.
Design your desired HTML table with a last row to show the radio buttons.
Like (very rough, without any styling)
Code:
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse:collapse;" width="100%">
<tbody>
<tr>
<td>Which profile do you prefer?</td>
<td><strong>Profile 1</strong></td>
<td><strong>Profile 2</strong></td>
</tr>
<tr>
<td>Name</td>
<td><strong>{PName1.shown}</strong></td>
<td><strong>{PName2.shown}</strong></td>
</tr>
...
<tr>
<td>Semester</td>
<td><strong>{PSem1.shown}</strong></td>
<td><strong>{PSem2.shown}</strong></td>
</tr>
<tr>
<td><b>Your choice</b></td>
<td> </td>
<td> </td>
</tr>
</tbody>
</table>
You show the texts of the profiles in the cells with {PName1.shown}, {PField2.shown},...
To move the radios into the table use this script
Code:
<script type="text/javascript" charset="utf-8">
$(document).on('ready pjax:scriptcomplete',function(){
// Identify this question
var thisQuestion = $('#question{QID}');
// Move the radios, you see they are inserted in the second and third column (td:eq(x)) of the last row (tr:last)
// And the first and second answer option are affected (answer-item:eq(x))
// Remember it is zero based.
$('.question-text table:eq(0) tr:last td:eq(1)', thisQuestion).append($('.subquestion-list .answers-list:eq(0) .answer-item:eq(0) *', thisQuestion));
$('.question-text table:eq(0) tr:last td:eq(2)', thisQuestion).append($('.subquestion-list .answers-list:eq(0) .answer-item:eq(1) *', thisQuestion));
// Some classes for presentation
$('.question-text table:eq(0) input:radio', thisQuestion).closest('td').addClass('answer-item radio-item text-center radio');
$('.question-text table:eq(0) .radio-item label', thisQuestion).show();
// Click event on the table cells
$('.question-text table:eq(0) .radio-item', thisQuestion).on('click', function(e) {
$('input:radio', this).trigger('click');
});
$('.question-text table:eq(0) input:radio', thisQuestion).on('click', function(e) {
e.stopPropagation();
});
// Clean-up styles
$('.answer-container', thisQuestion).hide();
$('.question-text table:eq(0) .label-text', thisQuestion).remove();
$('.question-text table:eq(0) .radio-text', thisQuestion).css({
'cursor': 'pointer'
});
});
</script>
The big advantage is:
In the equations you only have to changes the indices
You can copy this question into all other groups without any changes.
This way you will get the following in the response table
You see the first profile (red): the character of the name and the codes of the four attributes
You see the second profile (blue): the character of the name and the codes of the four attributes
And in the next question the answer code.
Here the survey structure
Now it's your turn.
Try to create this.
If there are questions send the lss export (and not only two empty questions)
You see: In your first post you mentioned many attempts that failed. Why didn't you show them? Maybe there were real good ideas where only a minor tweak made them run.
And we always ask for lss exports (neither lsq nor lsg).
These other exports are language sensitive. You can only import them into a survey with the same base language.
So ease our work, that we don't have to guess a language, create a survey, create a group to be able to import a lsq export.
Furthermore these exports don't contain the survey wide settings that may be of importance, too.
Joffm
BTW:
If you prefer to use your csv file you may have a look at [url]
www.papaparse.com/
[/url]