Welcome to the LimeSurvey Community Forum

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

Repeated random order of subquestions for 2 array qs on separate pages / groups

  • driz
  • driz's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
6 months 4 weeks ago - 6 months 4 weeks ago #250763 by driz
Your LimeSurvey version: LimeSurvey Community Edition Version 6.2.5+230828 
Own server or LimeSurvey hosting: Own hosting
Survey theme/template: Modified version of fruity_twentythree
==================

Hi all,
I am trying to randomise the order of two array subquestions, maintaining the same randomised order.
The array questions have the same subquestions, however the second one has one additional question that should be always the last option.
Each of the array questions are in their own group. 

I tried applying some Javascript that worked for multiple response questions, but I know it is the wrong code as it will not work on the array question. I have tried searching in the forum, and Googling, but I struggled to find whether this is possible in LimeSurvey. 
Can someone point me in the right direction?

I have attached the copy of the survey I am working on. In this example I am working on questions Q8 and Q9. Q9 should have the same randomised order of the subquestions as Q8.
Last edit: 6 months 4 weeks ago by driz.

Please Log in to join the conversation.

  • driz
  • driz's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
6 months 3 weeks ago #250900 by driz
Anyone? Am I confusing you, or is there information missing in my question?

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 months 3 weeks ago #250927 by tpartner
Why do you attach a sample survey with 14 questions. It is faster and easier for the volunteers here to help if your sample survey only contains the relevant question(s).

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

  • driz
  • driz's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
6 months 3 weeks ago #250929 by driz
Apologies Tony, here is the survey structure with only the two questions.

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 months 3 weeks ago #250954 by tpartner
For the benefit of others, you are trying to save the order of sub-questions of a first array in a hidden short-text question. Then, in a later group, you retrieve that order and use it to manipulate the order of a second array.

It looks like the scripts you are using are for multiple-choice type questions.

For arrays, this should be the script in the first question:

Code:
<script type="text/javascript" data-author="Tony Partner">
  $(document).on('ready pjax:scriptcomplete',function(){
 
    //Identify the questions
    var thisQuestion = $('#question{QID}');
    var hiddenQuestion = $(thisQuestion).nextAll('.text-short:eq(0)');
 
    // Create an array of answer codes
    var answerCodes = [];
    $('tr.answers-list', thisQuestion).each(function(i) {
      answerCodes.push($(this).attr('id').split('X{QID}')[1]);
    });
 
    // Load the hidden question
    $('input:text', hiddenQuestion).val(answerCodes);
 
  });
</script>

This should be in the second question:

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

Sample survey attached: 

File Attachment:

File Name: limesurvey...9271.lss
File Size:70 KB


Another issue - LS 6.x uses Bootstrap 5 so, when hiding a question via a CSS class, use "d-none" instead of "hidden".

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: driz

Please Log in to join the conversation.

  • driz
  • driz's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
6 months 3 weeks ago - 6 months 3 weeks ago #250962 by driz
Thanks Tony, this is perfect. 

I adjusted the script for the second question to the following to make the last subquestion always be the last option in the randomised set.
Code:
<script type="text/javascript">
  $(document).on('ready pjax:scriptcomplete',function(){
 
    //Identify this question
    var thisQuestion = $('#question{QID}');
    var thisAnswerList = $('tr.answers-list:eq(0)', thisQuestion).parent();
 
  // Retrieve the answer codes from the "randomOrder2" question
    var answerCodes = '{randomOrder2}'.split(',');
 
    // Loop through the answer codes
    $.each(answerCodes, function(i, val) {
      // Move the answer item
      $(thisAnswerList).append($('tr.answers-list[id$="X{QID}'+val+'"]', thisQuestion));
    });
 
// The subquestion code to place in the last position
        var fixedCode = '14';
 
        // Move the "fixed" row to the end
      $(thisAnswerList).append($('tr.answers-list[id$="X{QID}'+fixedCode+'"]', thisQuestion));
 
  });
</script>
Last edit: 6 months 3 weeks ago by driz.

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose