Welcome to the LimeSurvey Community Forum

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

Randomize group of questions at random

  • Mon2016
  • Mon2016's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 4 months ago #209309 by Mon2016
Hello everyone,
As you can see, I am a very beginner in this world of Lime survey, I hope you have patience with me.
I am creating a survey where 10 marks will be shown in an answer
multiple and for each of the brands I made a group of questions that contain 10 different questions for each of them.

The dilemma is that I only need to show 3 groups of questions depending on the brands you have selected that you bought throughout the year, that is ...


If in question 1 you selected that you bought brand A and B, I only need to show group A and B
But if you selected that you bought 5 brands, A, B, C, D and E I only have to show as limit 3 groups of questions but randomly.

Does anyone have any tips that can help me solve this issue?

I would greatly appreciate it.

A hug to all
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 4 months ago #209314 by tpartner
Replied by tpartner on topic Randomize group of questions at random

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • Mon2016
  • Mon2016's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 4 months ago #209326 by Mon2016
Replied by Mon2016 on topic Randomize group of questions at random
Hi, Tony,

Thanks for your help, this works great for multiple choice questions, however I found that there are some questions that my client wants asked with a matrix question,

Here an example:


For this question it is a question of dragging those brands that select codes from 3 to 5. And choose only three random brands if they select more than three.

sorry I forgot to mention that for this survey I am using the version 2.50 Build 160414


Thanks Tony for your time and your great help
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 4 months ago #209337 by Joffm
Replied by Joffm on topic Randomize group of questions at random
Hi,
as this is a different question you should have opened a new thread.

But you can do it like this.
Code:
<script type="text/javascript" charset="utf-8">    
$(document).ready(function() {
 
function shuffleArray(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;
}
    // Identify the questions
    var thisQuestion = $('#question{QID}');
    var thisQuestionID = {QID};
    var str = $('#question{QID} input[type="text"]').val();
      var arr = str.split(', ');
 
                // Shuffle the array
    arr=shuffleArray(arr);
        anumbers = '#' + arr.slice(0,3).join(',');
    // Load the hidden questions with items from the array
    $('#question{QID} input[type="text"]').val(anumbers);
        $('#question{QID}').hide();  
 
    });
</script>

File Attachment:

File Name: limesurvey...8257.lss
File Size:31 KB


Have a look at the default answer of "Q0a".

screenshots:
1. More than three brands




2. Less than three brands




You see the dynamic text?

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • Mon2016
  • Mon2016's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 4 months ago #209340 by Mon2016
Replied by Mon2016 on topic Randomize group of questions at random
hi joffm,

thank you very much for your effort,

To make this work in each group of questions use the condition of each sub-question and put it in the relevant equation of each group and it works correctly.

you are a crack at this.

I give you a big hug.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 4 months ago - 3 years 4 months ago #209344 by Joffm
Replied by Joffm on topic Randomize group of questions at random
Yes, I remembered last night, that I forgot to say:
"The multiple question is an example to show how to use the relevance equation strpos(Q0,"A")>0."

Meaning you have to enter it into your groups.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 3 years 4 months ago by Joffm.
The topic has been locked.
  • Mon2016
  • Mon2016's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 4 months ago #209404 by Mon2016
Replied by Mon2016 on topic Randomize group of questions at random
Hi Joffm,

I have a question, I hope you can help me as always,

In Q0a which is where the default questions are, I see that this question in Version 2.50+ Build 160414 does not work if I hide it, since my survey is question by question and when hiding this question so that it does not show it, it does not validate for dragging the groups, is there a way that this works by hiding it, or is there a script that works for version 4.1.18 + 200416 I would like to do some testing with this version.

I appreciate you great help too.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 4 months ago - 3 years 4 months ago #209408 by Joffm
Replied by Joffm on topic Randomize group of questions at random

does not work if I hide it, since my survey is question by question and when hiding this question so that it does not show it

And this is the reason that we recommend to display "group by group" and put one question into each group.
So the look&feel is as "question by question", but you have the option to do these things where you need to have more than one question on a page though some are hidden by the javascript.

And really 4.1.18?
You know the use of 4.x. is not recommended for production. It is still unstable; and your version is more than half a year old.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 3 years 4 months ago by Joffm.
The topic has been locked.
  • Mon2016
  • Mon2016's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 4 months ago #209414 by Mon2016
Replied by Mon2016 on topic Randomize group of questions at random
Thank you very much joffm,
Create groups for each question to make it work.
Yes, I have seen many bugs with the 4x version,
Would you recommend me to continue with the 3x?

Thank you so much for all your help.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 4 months ago #209417 by Joffm
Replied by Joffm on topic Randomize group of questions at random
Yes, we recommend this.

And according to @holch, who is nearer at the developers:

I heard in the chat today that there will probably be a release candidate for the LS 4.4 soon (in the next few weeks / months?). So it should still be a bit longer until a stable version is reached.


Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose