Welcome to the LimeSurvey Community Forum

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

Take those marked in a multiple question.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 4 months ago #244798 by Joffm
Replied by Joffm on topic Take those marked in a multiple question.

Of the selected brands, I am only taking the first 5 to apply my next questions, which are Q21 and Q21a.

LimeSurvey does not store the order. So how do you decide which are the "first 5"?
At random?
Then there is a really short solution. If you have something else inmind, please, explain!

Do not "join" the brands in "eqBrands", but use the function "list" and assign the brands separated (physical - online) to a next question of type "multiple short text" (one subquestion for physical one for online. This question you hide with the css class "hidden"
I called it "strBrands" with subquestion codes "p" (physical" and "o" (online).
Now in "eqBrands" you assign with two equations.
{strBrands_p=list(if(Q13a_1=="Y","A",""), if(Q13a_3=="Y","C",""), if(Q13a_4=="Y","D",""),..., if(Q13a_43=="Y","q",""), if(Q13a_44=="Y","r",""), if(Q13a_46=="Y","t",""), if(Q13a_47=="Y","u",""))}

{strBrands_o=list(if(Q13a_2=="Y","B",""), if(Q13a_13=="Y","M",""), if(Q13a_16=="Y","P",""), if(Q13a_19=="Y","S",""), if(Q13a_37=="Y","k",""), if(Q13a_45=="Y","s",""))}

In this question you insert this script, which randomizes the brands and then displays only the first 5 into each subquestion.
Code:
<script type="text/javascript" charset="utf-8">
 
function shuffle(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;
}
 
    $(document).on('ready pjax:scriptcomplete',function(){
      var strp=$('#question{QID} input[type="text"]:eq(0)').val().replace(/\s+/g, '');
      var stro=$('#question{QID} input[type="text"]:eq(1)').val().replace(/\s+/g, '');
 
// Fill the arrays
      var arrp = strp.split(',');
      var arro = stro.split(',');
// Shuffle and truncate
      arrp = shuffle(arrp);
      arrp = arrp.slice(0,5).join('');
      arro = shuffle(arro);
      arro = arro.slice(0,5).join('');
// Fill the subquestion with the results
      $('#question{QID} input[type="text"]:eq(0)').val(arrp);
      $('#question{QID} input[type="text"]:eq(1)').val(arro);
      $('#ls-button-submit').trigger('click');
   });
</script>

Then you use the same equation to pipe the brands into your questions; instead of "eqBrands" you use "strBrands_p" and "strBrands_o".
Quickly changed with the "search and replace" button.

And you may use a question relevance using the string length, like
Q2101: strlen(strBrands_p)>0
Q2102: strlen(strBrands_p)>1
...

That's all.


By the way:
What is this?
count(Q13a_1.NAOK,Q13a_3.NAOK,Q13a_4.NAOK,Q13a_5.NAOK,Q13a_6.NAOK,Q13a_7.NAOK,Q13a_8.NAOK,Q13a_9.NAOK,Q13a_10.NAOK,Q13a_11.NAOK,Q13a_12.NAOK,Q13a_14.NAOK,Q13a_15.NAOK,Q13a_17.NAOK,Q13a_18.NAOK,Q13a_20.NAOK,Q13a_21.NAOK,Q13a_22.NAOK,Q13a_23.NAOK,Q13a_24.NAOK,Q13a_25.NAOK,Q13a_26.NAOK,Q13a_28.NAOK,Q13a_29.NAOK,Q13a_30.NAOK,Q13a_31.NAOK,Q13a_32.NAOK,Q13a_33.NAOK,Q13a_34.NAOK,Q13a_35.NAOK,Q13a_36.NAOK,Q13a_38.NAOK,Q13a_39.NAOK,Q13a_40.NAOK,Q13a_41.NAOK,Q13a_42.NAOK,Q13a_43.NAOK,Q13a_44.NAOK,Q13a_46.NAOK,Q13a_47.NAOK)==1 or count(Q13a_1.NAOK,Q13a_3.NAOK,Q13a_4.NAOK,Q13a_5.NAOK,Q13a_6.NAOK,Q13a_7.NAOK,Q13a_8.NAOK,Q13a_9.NAOK,Q13a_10.NAOK,Q13a_11.NAOK,Q13a_12.NAOK,Q13a_14.NAOK,Q13a_15.NAOK,Q13a_17.NAOK,Q13a_18.NAOK,Q13a_20.NAOK,Q13a_21.NAOK,Q13a_22.NAOK,Q13a_23.NAOK,Q13a_24.NAOK,Q13a_25.NAOK,Q13a_26.NAOK,Q13a_28.NAOK,Q13a_29.NAOK,Q13a_30.NAOK,Q13a_31.NAOK,Q13a_32.NAOK,Q13a_33.NAOK,Q13a_34.NAOK,Q13a_35.NAOK,Q13a_36.NAOK,Q13a_38.NAOK,Q13a_39.NAOK,Q13a_40.NAOK,Q13a_41.NAOK,Q13a_42.NAOK,Q13a_43.NAOK,Q13a_44.NAOK,Q13a_46.NAOK,Q13a_47.NAOK)==2 or
... more and more ...
count(Q13a_1.NAOK,Q13a_3.NAOK,Q13a_4.NAOK,Q13a_5.NAOK,Q13a_6.NAOK,Q13a_7.NAOK,Q13a_8.NAOK,Q13a_9.NAOK,Q13a_10.NAOK,Q13a_11.NAOK,Q13a_12.NAOK,Q13a_14.NAOK,Q13a_15.NAOK,Q13a_17.NAOK,Q13a_18.NAOK,Q13a_20.NAOK,Q13a_21.NAOK,Q13a_22.NAOK,Q13a_23.NAOK,Q13a_24.NAOK,Q13a_25.NAOK,Q13a_26.NAOK,Q13a_28.NAOK,Q13a_29.NAOK,Q13a_30.NAOK,Q13a_31.NAOK,Q13a_32.NAOK,Q13a_33.NAOK,Q13a_34.NAOK,Q13a_35.NAOK,Q13a_36.NAOK,Q13a_38.NAOK,Q13a_39.NAOK,Q13a_40.NAOK,Q13a_41.NAOK,Q13a_42.NAOK,Q13a_43.NAOK,Q13a_44.NAOK,Q13a_46.NAOK,Q13a_47.NAOK)==15



Doesn't it only mean: count>0?
And if you had read the manual about the variables "self" and "that", it is shortened to
count(that.Q13a.NAOK)>0

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • Mon2016
  • Mon2016's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 year 4 months ago #244799 by Mon2016
Replied by Mon2016 on topic Take those marked in a multiple question.
Hello Joffm

Thank you very much for your help, now you opened up a bigger picture than what I was looking for.

I tell you that I did what you indicated and everything seems to be correct, there is only something that I do not know if I have not done well, since in "strBrands_p" and "strBrands_o" it registers commas to separate each brand, so when using the relevant equation "strlen(strBrands_p)>0" I guess it's taking those commas and doesn't display Q21 questions well.

Can you help me figure out what I did wrong?

I am attaching my lss survey to see if you could guide me where I went wrong.


Thanks again for all your help.

​​​​​​​Moon

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 4 months ago #244800 by Joffm
Replied by Joffm on topic Take those marked in a multiple question.
Hi,

it registers commas to separate each brand

Exactly, this is what the "list" function does.
And it is necessary.
In the script you see this line
var arrp = strp.split(',');
Meaning: the comma separated text is inserted in an array and the comma is used as separator.

But: Where is the script in question "strBrands"

On the other hand you inserted ALL brands into strBrand_o. I thought only brands 2,13,16,19, 37,45 are online brands.


Joffm

 

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • Mon2016
  • Mon2016's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 year 4 months ago #244801 by Mon2016
Replied by Mon2016 on topic Take those marked in a multiple question.
Hello Joffm

Thank you very much, I thought that the script was only to randomize the answers,

I tell you that in the text of the question of Q21 and Q21a I replaced the "eqBrands" by the "strBrands_p" or the "strBrands_o" as the case may be and everything was displayed correctly.

I also thought that it would only apply for the codes that I mentioned to you. hehehehe, but I realized that there are many brands that handle both modalities, both physical and online.



The only thing that worries me is something, when doing the randomization of the brands it may be that the ones that were evaluated in Q21 I did not evaluate in Q21a since both are randomly shown differently.

Is there a way to make the randomization the same for both subquestions of strBrands?

Or, in your case, take the first 5 that you mark regardless of the order, only respecting the position of the list of brands?

Thanks again for all your help.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 4 months ago - 1 year 4 months ago #244804 by Joffm
Replied by Joffm on topic Take those marked in a multiple question.
Hi,
please, ask again, when you have a finalized workflow and a well defined algorithm which brands have to be displayed.
Let's say, in Q13a there are 4 physical brands (P1,P2,P3,P4), 3 online brands (O1,O2,O3) and 4 mixed brands (M1,M2,M3,M4) selected.
Which have to be displayed and where?
I should say:
Split the question and ask separately these two types of brands. In this case the mixed brands appear twice.
Or use subquestion relevance in Q21 ff:
Insert all subquestions (physical and online). To physical brands show one part of the subquestions, to online brands the other part and to these mixed brands show all. To do this you should recode your brands that you have easy subquestion relevance equations
It's up to you.
Only you know what is the goal of your survey.

I am a bit tired to answer to always changing requirements
You started with

so my solution is to only have 10 fixed variables and show the ones that I have selected in Q13a,


Then you changed to

Of the selected brands, I am only taking the first 5 to apply my next questions, which are Q21 and Q21a.
In these two questions, the 5 brands that they selected in Q13a are evaluated, but Q21 only applies to physical brands and Q21a only to online brands.

And now

but I realized that there are many brands that handle both modalities, both physical and online.



And you really should read the manual and study the sample surveys which you can download there.
Just to avoid questions that only arise because you  are not familiar with the basics of ExpressionScript.

Joffm
 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 year 4 months ago by Joffm.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 4 months ago #244806 by Joffm
Replied by Joffm on topic Take those marked in a multiple question.
Addition to the "mixed" brands.
Repondents who only used one channel can't answer the question to the other.
So, you should ask them, which channel the used (physical or online, or both).
This you can do by changing Q13a to an array(numbers) with checkbox layout.

And you should limit the number of brands in each column to 5. 
"Which of these brands did you mainly buy in the last 6 month? Please, select up to 5 in each channel."
Then everything is fine, clear and easy.

Joffm 
 

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose