Welcome to the LimeSurvey Community Forum

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

Can I select a random answer from a multiple choice question

  • davebostockgmail
  • davebostockgmail's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
6 years 3 months ago #161791 by davebostockgmail
I have a survey that has the following requirements

1) Survey is displayed question by question
2) I have a list of 20 brands with an other specify at the end in a multiple choice question
3) I need to ask a respondent about a randomly answered brand for a series of subsequent questions

So for example
B5a Which of the following have you heard of
apples
banana
pears

E1 What do you like about [Random from B5a]

I have looked through the solutions that have been provided in the past but these all include group by group with a hidden text question ... this will not work for me as we have over 100 questions so each would have to be moved into its own group.

Is this even possible?

Thanks in advance
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 3 months ago #161799 by holch
First of all: I assume that the random brand should be chosen from the ones answered, right? So only from the ones they have heard of?

Problem with question by question is where to "hide" the question that creates the randomness.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • davebostockgmail
  • davebostockgmail's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
6 years 3 months ago #161804 by davebostockgmail
That's correct Holch ... I have thought the best way to do this would be to create an array in JQuery using the answers given then create a random number from the number of answers given and then use that to select from the array and push that into a single choice question.
Unfortunately my Jquery skills are not that advanced.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 3 months ago - 6 years 3 months ago #161810 by Joffm
Hi,
you can do this with some equations.
I did this some time ago. Maybe not the best, but working.

1. Equation "eqmyString"
I create a string with the "join"-function.
{join(if(Q01_SQ001=="Y","01",""),if(Q01_SQ002=="Y","02",""),if(Q01_SQ003=="Y","03",""),if(Q01_SQ004=="Y","04",""),...)}
You see if the brand was selected the code is added to the string.
You will get something like "0306111417"

2. Equation "eqnBrands"
{count(that.Q01)}

I count the number of entered brands and get "eqnBrands". In this case 5.

3. Equation "eqRandom"
I create a random number (1-numberBrands)
{rand(1,eqnBrands)}
Let's say: 4

4. Equation "eqmyBrand"
I get the substring of my string depending on the random number (eqRandom)
{substr(eqmyString,2*(eqRandom-1),2)}.
In this case substr(eqmyString,6,2) and you get "14".

You have to set (eqRandom-1) because substr starts at position 0.

And in your next question you pipe in the name.?
What do you like about {if(eqmyBrand=="01","Apples",if(eqmyBrand=="02","Bananas",if(eqmyBrand=="03","Pears","")))}?


Best regards
Joffmn

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 6 years 3 months ago by Joffm.
The topic has been locked.
  • davebostockgmail
  • davebostockgmail's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
6 years 3 months ago #161811 by davebostockgmail
Amazing ... thank you so much ...
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 3 months ago #161816 by holch
Joffm, looks good. But where do you hide those equation type questions in a question by question environment?

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 3 months ago - 6 years 3 months ago #161821 by Joffm
Have a look at the sample.

Here it is question by question , and I did it group by group as well.

File Attachment:

File Name: limesurvey...2-18.lss
File Size:22 KB


Best regards
Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 6 years 3 months ago by Joffm.
The topic has been locked.
More
4 years 8 months ago #186363 by Nighthawlk
Hi there,
I tried to addapt Joffms solution for a question including text as answers
Everything is working for me, exept step one:
"1. Equation "eqmyString"
I create a string with the "join"-function.
{join(if(Q01_SQ001=="Y","01",""),if(Q01_SQ002=="Y","02",""),if(Q01_SQ003=="Y","03",""))}
"

My first addaption is looking like this:
{join(if(!is_empty(NW1_SQ001),
if(!is_empty(NW1_SQ002),
if(!is_empty(NW1_SQ003))))}

Here, limesurvey doesn't accept the commas

Afterwards, I tried out an other addaption like this:
{ ... if(!is_empty(NW1_SQ003),3,
if(!is_empty(NW1_SQ002),2,
if(!is_empty(NW1_SQ001),1))))}

This was working yesterday. Today it is only working when I have NW1_SQ018 answered.

Can you help me finding the mistakes?
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 8 months ago #186391 by Joffm

{join(if(!is_empty(NW1_SQ001),
if(!is_empty(NW1_SQ002),
if(!is_empty(NW1_SQ003))))}
Here, limesurvey doesn't accept the commas


LimeSurvey does accept comma, but your usage of the if-statements seems to be wrong.
We don't see your sample.

Remember:
if(condition,what if true,what if false)

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 8 months ago #186397 by DenisChenu

Joffm wrote: Remember:
if(condition,what if true,what if false)

Just a correction :
Code:
if(condition,what if true)
OR
Code:
if(condition,what if true,what if false)
Since 3.0.2 LimeSurvey version :)

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
More
4 years 8 months ago #186439 by Nighthawlk
Thank you very much for your answers.

Remember:
if(condition,what if true,what if false)

that would mean, my example 2 should work properly although it doesn't, right?

We don't see your sample

I also attached my sample for a better comprehensibility of the appearing errors

It would be very nice, if you could find the time for a deeper look inside the code

File Attachment:

File Name: limesurvey...5926.lsg
File Size:19 KB
The topic has been locked.
More
4 years 8 months ago #186443 by Nighthawlk
PS: see question COUNT1
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose