- Posts: 64
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Split random order
- Andrea01
- Topic Author
- Offline
- Senior Member
Less
More
5 years 9 months ago #170957
by Andrea01
Split random order was created by Andrea01
Is it possible to split random order for arrays, multiple choice and radio list questions?
For example question code Q1with subquestions
sq001 subquestion1
sq002 subquestion2
sq003 subquestion3
sq004 subquestion4
sq005 subquestion5
sq006 subquestion6
Subquestion1 to 3 should be in random order between themselves and additionally subquestion4 to 6 should be in their own random order.
Thanks in advance and best regards
Andrea
For example question code Q1with subquestions
sq001 subquestion1
sq002 subquestion2
sq003 subquestion3
sq004 subquestion4
sq005 subquestion5
sq006 subquestion6
Subquestion1 to 3 should be in random order between themselves and additionally subquestion4 to 6 should be in their own random order.
Thanks in advance and best regards
Andrea
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12881
- Thank you received: 3965
5 years 9 months ago #170959
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Split random order
Hi, Andrea,
shortest and easiest way:
split it into two questions.
Joffm
shortest and easiest way:
split it into two questions.
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
- Andrea01
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 64
- Thank you received: 0
5 years 9 months ago #170960
by Andrea01
Replied by Andrea01 on topic Split random order
Thank you Joffm, I habe been thinking about this solution, but I thought there might be a more elegant way.
Also, I just discovered, that I put my request in the wrong forum. Can you please move it to forum "Can I do this with LimeSurvey" or should I post again.
Thanks,
Andrea
Also, I just discovered, that I put my request in the wrong forum. Can you please move it to forum "Can I do this with LimeSurvey" or should I post again.
Thanks,
Andrea
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12881
- Thank you received: 3965
5 years 9 months ago #170961
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Split random order
Hi, Andrea,
I know it's not very elegent.
But at the moment we only have workarounds for half of it: randomized first three, fixed second three.
Don't worry about the section, as long as you post in the correct language.
To be honest: Unfortunately nearly nobody seems to care about the intended content of the first three sections.
Best regards
Joffm
I know it's not very elegent.
But at the moment we only have workarounds for half of it: randomized first three, fixed second three.
Don't worry about the section, as long as you post in the correct language.
To be honest: Unfortunately nearly nobody seems to care about the intended content of the first three sections.
Best regards
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10099
- Thank you received: 3589
5 years 9 months ago #170962
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Split random order
You could do it with JavaScript but the script details would depend on the LimeSurvey version used.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- Andrea01
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 64
- Thank you received: 0
5 years 9 months ago #170971
by Andrea01
Replied by Andrea01 on topic Split random order
Hi Tony,
For this survey still using limesurvey2.6.7-lts+171212.
Thanks and best regards
Andrea
For this survey still using limesurvey2.6.7-lts+171212.
Thanks and best regards
Andrea
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10099
- Thank you received: 3589
5 years 9 months ago - 5 years 9 months ago #171003
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Split random order
Place this in template.js:
Place something like this in the source of a multiple-choice question (adjust the sub-question codes as required):
Place something like this in the source of an array question (adjust the sub-question codes as required):
Place something like this in the source of a list-radio question (adjust the answer codes as required):
Sample survey attached:
Code:
function shuffleArray(array) { for (var i = array.length - 1; i > 0; i--) { var j = Math.floor(Math.random() * (i + 1)); var temp = array[i]; array[i] = array[j]; array[j] = temp; } return array; }
Place something like this in the source of a multiple-choice question (adjust the sub-question codes as required):
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Identify this question var qID = {QID}; var thisQuestion = $('#question'+qID); // First group of sub-question codes var sqCodes1 = ['SQ001', 'SQ002', 'SQ003']; // Second group of sub-question codes var sqCodes2 = ['SQ004', 'SQ005', 'SQ006']; // Shuffle the subquestions shuffleArray(sqCodes1); shuffleArray(sqCodes2); // Insert the rows in the shuffled order $(sqCodes1).each(function(i, val){ $('.subquestions-list', thisQuestion).append($('.question-item[id$="X'+qID+val+'"]', thisQuestion)); }); $(sqCodes2).each(function(i, val){ $('.subquestions-list', thisQuestion).append($('.question-item[id$="X'+qID+val+'"]', thisQuestion)); }); }); </script>
Place something like this in the source of an array question (adjust the sub-question codes as required):
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Identify this question var qID = {QID}; var thisQuestion = $('#question'+qID); // First group of sub-question codes var sqCodes1 = ['SQ001', 'SQ002', 'SQ003']; // Second group of sub-question codes var sqCodes2 = ['SQ004', 'SQ005', 'SQ006']; // Shuffle the subquestions shuffleArray(sqCodes1); shuffleArray(sqCodes2); // Insert the rows in the shuffled order $(sqCodes1).each(function(i, val){ $('table.subquestions-list', thisQuestion).append($('.answers-list[id$="X'+qID+val+'"]', thisQuestion)); }); $(sqCodes2).each(function(i, val){ $('table.subquestions-list', thisQuestion).append($('.answers-list[id$="X'+qID+val+'"]', thisQuestion)); }); }); </script>
Place something like this in the source of a list-radio question (adjust the answer codes as required):
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Identify this question var qID = {QID}; var thisQuestion = $('#question'+qID); // First group of answer codes var answerCodes1 = ['A1', 'A2', 'A3']; // Second group of answer codes var answerCodes2 = ['A4', 'A5', 'A6']; // Shuffle the subquestions shuffleArray(answerCodes1); shuffleArray(answerCodes2); // Insert the rows in the shuffled order $(answerCodes1).each(function(i, val){ $('.answers-list', thisQuestion).append($('.answer-item[id$="X'+qID+val+'"]', thisQuestion)); }); $(answerCodes2).each(function(i, val){ $('.answers-list', thisQuestion).append($('.answer-item[id$="X'+qID+val+'"]', thisQuestion)); }); }); </script>
Sample survey attached:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
Last edit: 5 years 9 months ago by tpartner.
The topic has been locked.
- Andrea01
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 64
- Thank you received: 0
5 years 9 months ago #171005
by Andrea01
Replied by Andrea01 on topic Split random order
Works perfectly.
Thank you Tony, you are the best.
Thank you Tony, you are the best.
The topic has been locked.
- Andrea01
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 64
- Thank you received: 0
3 years 10 months ago #201255
by Andrea01
Replied by Andrea01 on topic Split random order
Is there a way to split random order in Version 3.22.18+200603?
Thanks and best regards
Thanks and best regards
The topic has been locked.
- Andrea01
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 64
- Thank you received: 0
3 years 10 months ago #201370
by Andrea01
Replied by Andrea01 on topic Split random order
I modified the code provided by Tony and had sucess, it works in version 3.22.
Please find the code below for 3 groups, subquestions order by random in each group.
BUT: Is there a possibility for random order the groups too?
Would be perfect if I could random order groups and subquestions within the group!
Could anyone help?
thx, Andrea
<script type="text/javascript" charset="utf-8">
function shuffleArray(array) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array;
array = array[j];
array[j] = temp;
}
return array;
}
$(document).on('ready pjax:scriptcomplete',function(){
// Identify this question
var qID = {QID};
var thisQuestion = $('#question'+qID);
// First group of sub-question codes
var sqCodes1 = ;
// Second group of sub-question codes
var sqCodes2 = ;
var sqCodes3 = ;
// Shuffle the subquestions
shuffleArray(sqCodes1);
shuffleArray(sqCodes2);
shuffleArray(sqCodes3);
// Insert the rows in the shuffled order
$(sqCodes1).each(function(i, val){
$('.answers-list[id$=X'+qID+val+']', thisQuestion).appendTo($('table.subquestion-list', thisQuestion));
});
$(sqCodes2).each(function(i, val){
$('.answers-list[id$=X'+qID+val+']', thisQuestion).appendTo($('table.subquestion-list', thisQuestion));
});
$(sqCodes3).each(function(i, val){
$('.answers-list[id$=X'+qID+val+']', thisQuestion).appendTo($('table.subquestion-list', thisQuestion));
});
});
</script>
Please find the code below for 3 groups, subquestions order by random in each group.
BUT: Is there a possibility for random order the groups too?
Would be perfect if I could random order groups and subquestions within the group!
Could anyone help?
thx, Andrea
<script type="text/javascript" charset="utf-8">
function shuffleArray(array) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array;
array = array[j];
array[j] = temp;
}
return array;
}
$(document).on('ready pjax:scriptcomplete',function(){
// Identify this question
var qID = {QID};
var thisQuestion = $('#question'+qID);
// First group of sub-question codes
var sqCodes1 = ;
// Second group of sub-question codes
var sqCodes2 = ;
var sqCodes3 = ;
// Shuffle the subquestions
shuffleArray(sqCodes1);
shuffleArray(sqCodes2);
shuffleArray(sqCodes3);
// Insert the rows in the shuffled order
$(sqCodes1).each(function(i, val){
$('.answers-list[id$=X'+qID+val+']', thisQuestion).appendTo($('table.subquestion-list', thisQuestion));
});
$(sqCodes2).each(function(i, val){
$('.answers-list[id$=X'+qID+val+']', thisQuestion).appendTo($('table.subquestion-list', thisQuestion));
});
$(sqCodes3).each(function(i, val){
$('.answers-list[id$=X'+qID+val+']', thisQuestion).appendTo($('table.subquestion-list', thisQuestion));
});
});
</script>
Attachments:
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10099
- Thank you received: 3589
3 years 9 months ago - 3 years 9 months ago #201434
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Split random order
This will also randomize the order of the sub-question groups:
Sample survey attached:
Code:
<script type="text/javascript" charset="utf-8"> function shuffleArray(array) { for (var i = array.length - 1; i > 0; i--) { var j = Math.floor(Math.random() * (i + 1)); var temp = array[i]; array[i] = array[j]; array[j] = temp; } return array; } $(document).on('ready pjax:scriptcomplete',function(){ // Identify this question var qID = {QID}; var thisQuestion = $('#question'+qID); var sqGroupIndexes = [1, 2, 3]; // The groups of sub-codes var sqCodes = { 1: ['1', '2', '3'], 2: ['4','5', '6'], 3: ['7','8'] } // Shuffle the arrays shuffleArray(sqGroupIndexes)[1]; shuffleArray(sqCodes[1]); shuffleArray(sqCodes[2]); shuffleArray(sqCodes[3]); // Loop though the randomized indexes $.each(sqGroupIndexes, function(index, val) { // Insert the rows in the shuffled order $.each(sqCodes[val], function(index, val){ $('.answers-list[id$=X'+qID+val+']', thisQuestion).appendTo($('table.subquestion-list', thisQuestion)); }); }); }); </script>
Sample survey attached:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
Last edit: 3 years 9 months ago by tpartner.
The topic has been locked.
- Andrea01
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 64
- Thank you received: 0
3 years 9 months ago #201489
by Andrea01
Replied by Andrea01 on topic Split random order
Works perfectly. Thank you so much Tony.
Best regards
Andrea
Best regards
Andrea
The topic has been locked.