Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Same randomization order for following questions

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 8 months ago #188041 by tpartner
Again we ask, please provide your LimeSurvey version and a small sample survey.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • HalloHans
  • HalloHans's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 8 months ago #188042 by HalloHans
Replied by HalloHans on topic Same randomization order for following questions
Thanks, I am using LimeSurvey Version 3.17.13.

A sample survey is attached.
Thanks in advance
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 8 months ago #188044 by tpartner
The script in the first question remains the same.

This is the script for the array question:

Code:
<script type="text/javascript" charset="utf-8">
  $(document).on('ready pjax:scriptcomplete',function(){
 
    //Identify this question
    var thisQuestion = $('#question{QID}');
    var thisAnswerList = $('table.subquestion-list tbody:eq(0)', thisQuestion);
 
    // Retrieve the answer codes from the "randomOrder" question
    var answerCodes = '{randomOrder}'.split(',');
 
    // Loop through the answer codes
    $.each(answerCodes, function(i, val) {
      // Move the array row
      $(thisAnswerList).append($('tr.answers-list[id$="X{QID}'+val+'"]', thisQuestion));
    });
 
  });
</script>

Here is your sample survey back with that change:

File Attachment:

File Name: limesurvey...9911.lss
File Size:33 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • HalloHans
  • HalloHans's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 8 months ago #188048 by HalloHans
Replied by HalloHans on topic Same randomization order for following questions
Thanks a lot for your help, it works perfectly.
The topic has been locked.
More
4 years 8 months ago #188087 by stephanied
Replied by stephanied on topic Same randomization order for following questions
I've followed the steps described above and unfortunately I am unable to get it to work. Similar to those above, I have version 3.17.13 and I've made sure that the AJAX theme option is disabled.

Can someone please take a look at the sample survey I've attached to see if I'm missing something?
I've attempted to use the codes on this thread and also here
www.limesurvey.org/forum/can-i-do-this-w...he-same-random-order
which is why the first two questions are multiple choice questions, followed by a list question, hidden short response, second list question and finally the array. None of which are successfully maintaining randomization sequence.

I greatly appreciate the help!
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 8 months ago #188090 by Joffm
Hi, Stephanie,
Your sample survey doesn't contain any javascript.

You placed all questions into one group which is not the fact in Tony's samples.
Your question LISThidden stores the codes of question LIST1. Here the codes are "A1", "A2",...
If you display the hidden question you will see, how they are stored.
But your array question uses the subquestion codes "SQ001", "SQ002", ...
If you rename your subquestion codes to "A1", "A2",... and structure the survey into several groups it works fine.

This for your single/single and single/array randomization.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
More
4 years 7 months ago #188134 by stephanied
Replied by stephanied on topic Same randomization order for following questions
Thanks Joffm!
I'm not sure why I haven't done this in the past, but I imported the lss to see the exact differences :blush: It worked perfectly once I imported and now I know what to do in the future. Just as a side note, I've always put my JS in the source of the help box, never in the source of the question, and have had no issues with doing so.

Is it possible to take this one step further and have the array question in the same group as the radio list question? If not, no worries, I am still very pleased with the results.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 7 months ago - 4 years 7 months ago #188194 by tpartner

Is it possible to take this one step further and have the array question in the same group as the radio list question?


To maintain the same order in a multiple-choice as the previous multiple-choice on the same page, add this script to the second multiple-choice question:

Code:
<script type="text/javascript" charset="utf-8">
 
  $(document).on('ready pjax:scriptcomplete',function(){
 
    // Identify the questions
    var thisQID = {QID};
    var thisQuestion = $('#question'+thisQID);
    var prevQuestion = $(thisQuestion).prevAll('.multiple-opt:eq(0)');
    var prevQID = $(prevQuestion).attr('id').replace(/question/, '');
 
    // Loop through the previous question sub-questions
    $('.answer-item', prevQuestion).each(function(i) {
      // Move the  sub-questions
      var thisCode = $(this).attr('id').split('X'+prevQID)[1];
      $('.answers-list ul:eq(0)', thisQuestion).append($('.answer-item[id$="X'+thisQID+thisCode+'"]', thisQuestion));
    });
  });
</script>

To maintain the same order in a list-radio as the previous list-radio on the same page, add this script to the second list-radio question:

Code:
<script type="text/javascript" charset="utf-8">
 
  $(document).on('ready pjax:scriptcomplete',function(){
 
    // Identify the questions
    var thisQID = {QID};
    var thisQuestion = $('#question'+thisQID);
    var prevQuestion = $(thisQuestion).prevAll('.list-radio:eq(0)');
    var prevQID = $(prevQuestion).attr('id').replace(/question/, '');
 
    // Loop through the previous question answers
    $('.answer-item', prevQuestion).each(function(i) {
      // Move the  sub-questions
      var thisCode = $(this).attr('id').split('X'+prevQID)[1];
      $('.answers-list ul:eq(0)', thisQuestion).append($('.answer-item[id$="X'+thisQID+thisCode+'"]', thisQuestion));
    });
  });
</script>

To maintain the same order in an array as the previous list-radio on the same page, add this script to the array question:

Code:
<script type="text/javascript" charset="utf-8">
 
  $(document).on('ready pjax:scriptcomplete',function(){
 
    // Identify the questions
    var thisQID = {QID};
    var thisQuestion = $('#question'+thisQID);
    var prevQuestion = $(thisQuestion).prevAll('.list-radio:eq(0)');
    var prevQID = $(prevQuestion).attr('id').replace(/question/, '');
 
    // Loop through the previous question answers
    $('.answer-item', prevQuestion).each(function(i) {
      // Move the  sub-questions
      var thisCode = $(this).attr('id').split('X'+prevQID)[1];
      $('table.subquestion-list tbody:eq(0)', thisQuestion).append($('.answers-list[id$="X'+thisQID+thisCode+'"]', thisQuestion));
    });
  });
</script>

Here is your sample survey back with those scripts incorporated:

File Attachment:

File Name: limesurvey...5511.lss
File Size:32 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 4 years 7 months ago by tpartner.
The topic has been locked.
More
4 years 6 months ago - 4 years 6 months ago #189403 by hamstr
Hi everyone! I've tried to implement tpartner's workaround for multiple choice questions. However, while recording the order in a hidden short text question works perfectly fine, I struggle to transfer it to the following questions. Does anyone know which adaptions to step 4 are necessary to apply the code to mc-questions that are not included in the same question group? Any kind of help is greatly appreciated!

I'm using version 2.64.

tpartner wrote:

4) Add this script to the source of following list-radio questions:

Code:
<script type="text/javascript" charset="utf-8">
  $(document).on('ready pjax:scriptcomplete',function(){
 
    //Identify this question
    var thisQuestion = $('#question{QID}');
    var thisAnswerList = $('li.answer-item:eq(0)', thisQuestion).parent();
 
    // Retrieve the answer codes from the "randomOrder" question
    var answerCodes = '{randomOrder}'.split(',');
 
    // Loop through the answer codes
    $.each(answerCodes, function(i, val) {
      // Move the answer item
      $(thisAnswerList).append($('li.answer-item[id$="X{QID}'+val+'"]', thisQuestion));
    });
 
  });
</script>

Last edit: 4 years 6 months ago by hamstr.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 6 months ago #189412 by tpartner
Can you attach a small sample survey (.lss file) containing only the relevant questions and your code?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
4 years 6 months ago - 4 years 6 months ago #189420 by hamstr
Thanks for the fast reply, Tony! Please see attachment for the .lss-file.
Last edit: 4 years 6 months ago by hamstr.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 6 months ago #189436 by tpartner
I cannot test in 2.64 but can it 2.73.0.

Part of the problem is that you display the questions in columns.

This should maintain the order in multiple-choice questions, in different groups, using columns, in version 2.73.0:

Code:
<script type="text/javascript" charset="utf-8">
       $(document).ready(function(){
 
    //Identify this question
    var thisQuestion = $('#question{QID}');
    var thisAnswerList = $('.answer-item:eq(0)', thisQuestion).parent();
 
    // Determine the number of items in the first column
    var rowCount = $('.multiple-choice-container > div:eq(0) .question-item', thisQuestion).length;
 
    // Retrieve the answer codes from the "randomOrder" question
    var answerCodes = '{randomOrder}'.split(',');
 
    // Loop through the answer codes
    var row = 0;
    var column = 0;
    $.each(answerCodes, function(i, val) {
 
      // Move the answer item
      $('.multiple-choice-container > div:eq('+column+') > div', thisQuestion).append($('.answer-item[id$="X{QID}'+val+'"]', thisQuestion).parent());
 
      if(row < (rowCount-1)) {
        row++;
      }
      else {
        // Increment the column
        row = 0;
        column++;
      }
    });
 
  });
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...8429.lss
File Size:73 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose