- Posts: 166
- Thank you received: 26
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
- Topic Author
- Offline
- Elite Member
Less
More
6 years 4 months ago #161791
by davebostockgmail
Can I select a random answer from a multiple choice question was created 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
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 11661
- Thank you received: 2742
6 years 4 months ago #161799
by holch
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Replied by holch on topic Can I select a random answer from a multiple choice question
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.
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
- Topic Author
- Offline
- Elite Member
Less
More
- Posts: 166
- Thank you received: 26
6 years 4 months ago #161804
by davebostockgmail
Replied by davebostockgmail on topic Can I select a random answer from a multiple choice question
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.
Unfortunately my Jquery skills are not that advanced.
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12943
- Thank you received: 3979
6 years 4 months ago - 6 years 4 months ago #161810
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Can I select a random answer from a multiple choice question
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
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 4 months ago by Joffm.
The topic has been locked.
- davebostockgmail
- Topic Author
- Offline
- Elite Member
Less
More
- Posts: 166
- Thank you received: 26
6 years 4 months ago #161811
by davebostockgmail
Replied by davebostockgmail on topic Can I select a random answer from a multiple choice question
Amazing ... thank you so much ...
The topic has been locked.
- holch
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 11661
- Thank you received: 2742
6 years 4 months ago #161816
by holch
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Replied by holch on topic Can I select a random answer from a multiple choice question
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12943
- Thank you received: 3979
6 years 4 months ago - 6 years 4 months ago #161821
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Can I select a random answer from a multiple choice question
Have a look at the sample.
Here it is question by question , and I did it group by group as well.
Best regards
Joffm
Here it is question by question , and I did it group by group as well.
Best regards
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:
Last edit: 6 years 4 months ago by Joffm.
The topic has been locked.
- Nighthawlk
- Offline
- New Member
Less
More
- Posts: 6
- Thank you received: 0
4 years 9 months ago #186363
by Nighthawlk
Replied by Nighthawlk on topic Can I select a random answer from a multiple choice question
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?
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12943
- Thank you received: 3979
4 years 9 months ago #186391
by Joffm
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
Replied by Joffm on topic Can I select a random answer from a multiple choice question
{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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13648
- Thank you received: 2491
4 years 9 months ago #186397
by DenisChenu
OR
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.
Replied by DenisChenu on topic Can I select a random answer from a multiple choice question
Just a correction :Joffm wrote: Remember:
if(condition,what if true,what if false)
Code:
if(condition,what if true)
Code:
if(condition,what if true,what if false)
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.
- Nighthawlk
- Offline
- New Member
Less
More
- Posts: 6
- Thank you received: 0
4 years 9 months ago #186439
by Nighthawlk
Replied by Nighthawlk on topic Can I select a random answer from a multiple choice question
Thank you very much for your answers.
It would be very nice, if you could find the time for a deeper look inside the code
that would mean, my example 2 should work properly although it doesn't, right?Remember:
if(condition,what if true,what if false)
I also attached my sample for a better comprehensibility of the appearing errorsWe don't see your sample
It would be very nice, if you could find the time for a deeper look inside the code
The topic has been locked.
- Nighthawlk
- Offline
- New Member
Less
More
- Posts: 6
- Thank you received: 0
4 years 9 months ago #186443
by Nighthawlk
Replied by Nighthawlk on topic Can I select a random answer from a multiple choice question
PS: see question COUNT1
The topic has been locked.