Welcome to the LimeSurvey Community Forum

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

randomization of particular subquestions in an array question

  • romankoflerh
  • romankoflerh's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
5 years 11 months ago #167379 by romankoflerh
Hello,

I'm using an array questions that has 18 subquestions. I want to randomize 17 subquestions (1-17) but the last one should always remain in the last place. Number 18 is not an exclusive option though.

Is there a possibility to do this?

thanks for your help
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 11 months ago #167383 by Joffm
Hi,

here you find it:
www.limesurvey.org/forum/can-i-do-this-w...few-at-bottom#157567
with a working example attached.

Two screenshots:




Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • romankoflerh
  • romankoflerh's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
5 years 11 months ago #167414 by romankoflerh
Hello Joffm,

thanks a lot for your answer! It works fine for the array type question. However, now I need the same for a multiple choice question. According to the code you sent it should also work for such question type. Nevertheless, even in the example survey it only works for array but not multiple choice. Might be it's because of the limesurvey version I'm using (3.6.2)?

I also attached the file (it's Q3)

Maybe you or someone else has an idea - would be highly appreciated.
Thanks for your help!
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 11 months ago - 5 years 11 months ago #167437 by tpartner
There have been HTML structure changes in 3.x so the script now needs to like this:

Code:
<script type="text/javascript" charset="utf-8">
  $(document).on('ready pjax:scriptcomplete',function(){
 
    // Identify this question
    var qID = {QID};
    var thisQuestion = $('#question'+qID);
 
    // Define the sub-question codes to be placed last
    var lastItems = ['SQ006', 'SQ007', 'SQ008'];
 
    // Loop through those sub-question codes 
    $.each(lastItems, function(i, val) {
      // Move that item to the end of the list
      // Multi-choice question
      if($(thisQuestion).hasClass('multiple-opt')) {
        $('.question-item[id$=X'+qID+val+']', thisQuestion).appendTo($('.question-item[id$=X'+qID+val+']', thisQuestion).parent());
      }
      // Array question
      if($(thisQuestion).hasClass('array-flexible-row')) {
        $('.answers-list[id$=X'+qID+val+']', thisQuestion).appendTo($('table.subquestion-list tbody:last', thisQuestion));
      }
      // List-radio question
      if($(thisQuestion).hasClass('list-radio')) {
        $('.answer-item[id$=X'+qID+val+']', thisQuestion).appendTo($('.answer-item[id$=X'+qID+val+']', thisQuestion).parent());
      }
    });  
  });
</script>

Here is your sample survey back with those changes:

File Attachment:

File Name: limesurvey...8862.lss
File Size:39 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 5 years 11 months ago by tpartner.
The topic has been locked.
  • romankoflerh
  • romankoflerh's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
5 years 11 months ago #167567 by romankoflerh
Works perfectly.
Thank you very much!
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose