Welcome to the LimeSurvey Community Forum

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

How to Selected 5 option from Multiple choice Question

More
3 weeks 1 day ago #273842 by rajkumar_dms
Please help us help you and fill where relevant:
Your LimeSurvey version: [see right hand bottom of your LimeSurvey admin screen]
Own server or LimeSurvey hosting:Cloud
Survey theme/template:
==================
I Have a multiple choice having 15 option and if someone selected 10 option i need to pick only 5 option randomly and one more things if code 5 is selected then it should be selected in random 5 option

Please Log in to join the conversation.

More
3 weeks 1 day ago #273843 by Joffm
Hi,
as usual, you'd send a small sample survey with these questions (lss export)

Joffm

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

Please Log in to join the conversation.

More
3 weeks 1 day ago #273844 by rajkumar_dms
here is the lss export

Please Log in to join the conversation.

More
3 weeks 1 day ago - 3 weeks 1 day ago #273849 by Joffm
Here my proposal (with javascript)

File Attachment:

File Name: limesurvey...94JJ.lss
File Size:68.37 KB

 


There is also a solution without javascript, only ExpressionScript. (if you prefer this)

Joffm
 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 3 weeks 1 day ago by Joffm.

Please Log in to join the conversation.

More
3 weeks 1 day ago #273859 by rajkumar_dms
Thanks joffm,

Can share the same without java script

Please Log in to join the conversation.

More
2 weeks 6 days ago #273870 by Joffm
Hi,
here a slightly improved sample.
 

File Attachment:

File Name: limesurvey...94_J.lss
File Size:68.34 KB


And a solution with only ExpressionScript can look like this
A. In a group (GCalc) create a (hidden) question of type "multiple short text" (QC). (This is used as a container for the interim results)
With these subquestions
 

B. Create a (hidden) question of type "equation".
In this question insert all expressions you need.
1. The first is to enter all selected subquestions of Q00 into base 1, like
{QC_b1=join(if(Q00_1=='Y','A',''), if(Q00_2=='Y','B',''), if(Q00_3=='Y','C',''), if(Q00_4=='Y','D',''), if(Q00_6=='Y','F',''), if(Q00_7=='Y','G',''),if(Q00_8=='Y','H',''),if(Q00_9=='Y','I',''),if(Q00_10=='Y','J',''),if(Q00_11=='Y','K',''),if(Q00_12=='Y','L',''),if(Q00_13=='Y','M',''),if(Q00_14=='Y','N',''),if(Q00_15=='Y','O',''))}
If the subquestion was selected you join a capital character (this is only to avoid the handling of two digits, as there are 15 subquestions)
And you see that the 5th subquestion is not handled. 
You will get something like "BDGIMN" in QC_b1.

2. Create a random number from 1 to the length of this string (use functions "strlen" and "rand)
3. Store the character at this place into QC_n1 (the first number) (use function "substr")
Both you can handle in one expression like
{QC_n1=substr(QC_b1,rand(1,strlen(QC_b1))-1,1)}
4. Join this "number" to the string in QC_final
{QC_final=join(QC_final,QC_n1)}
5. Create a new "base 1" (the previous string without the just selected character) (use function (str_replace")
{QC_b1=str_replace(QC_n1,"",QC_b1)}

Repeat these steps four times.

C. Now we handle subquestion 5
If subquestion 5 was selected in Q00, join "#E" to the actual value in QC_final, but store only five characters (+ '#')
If subquestion 5 was not selected in Q00, fine, we only join a trailing '#'.
{QC_final=if(Q00_5=="Y",join('#E',substr(QC_final,0,4)),join('#',QC_final))}

Now you will get something like "#EBHL" in "QC_final.
This first '#' avoids a value of 0, when checking this string.with "strpos"; 0 also means "not found"

And your subquestion relevance is like
strpos(QC_final,"A")>0
strpos(QC_final,"B")>0
...


Joffm

To avoid issues if the respondent is allowed to "go back", empty "QC_final" at the beginning of the equations.
Just: {QC_final=""}

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

Please Log in to join the conversation.

More
2 weeks 5 days ago - 2 weeks 5 days ago #273872 by Joffm
Here two different approaches (only ExpressionScript)
The ideas are to assign random numbers to the selected  subquestions and then take the five lowest numbers.
This is similar to the javascript approach where we shuffled the array.

1. Here we calculate a max value. Only subquestions with lower numbers are displayed. 
Create a (hidden) question (QC) of type "multiple short text" with 21 subquestion (15 to store the random number - 1,2,3,..., 5 to store the lowest, second lowest, ... - m1, m2, ...number, and the "max".
Create a (hidden) question of type equation with 

First we assign random numbers{QC_1 = if(is_empty(QC_1), rand(1,10000), QC_1)}
{QC_2 = if(is_empty(QC_2), rand(1,10000), QC_2)}
{QC_3 = if(is_empty(QC_3), rand(1,10000), QC_3)}
{QC_4 = if(is_empty(QC_4), rand(1,10000), QC_4)}
{QC_5 = 999999}
{QC_6 = if(is_empty(QC_6), rand(1,10000), QC_6)}
{QC_7 = if(is_empty(QC_7), rand(1,10000), QC_7)}
{QC_8 = if(is_empty(QC_8), rand(1,10000), QC_8)}
{QC_9 = if(is_empty(QC_9), rand(1,10000), QC_9)}
{QC_10 = if(is_empty(QC_10), rand(1,10000), QC_10)}
{QC_11 = if(is_empty(QC_11), rand(1,10000), QC_11)}
{QC_12 = if(is_empty(QC_12), rand(1,10000), QC_12)}
{QC_13 = if(is_empty(QC_13), rand(1,10000), QC_13)}
{QC_14 = if(is_empty(QC_14), rand(1,10000), QC_14)}
{QC_15 = if(is_empty(QC_15), rand(1,10000), QC_15)}


QC_5 has already a number that is out of the usual range.
Now all not selected subquestion get this value

{QC_1 = if(Q00_1=="Y",QC_1,999999)}
{QC_2 = if(Q00_2=="Y",QC_2,999999)}
{QC_3 = if(Q00_3=="Y",QC_3,999999)}
{QC_4 = if(Q00_4=="Y",QC_4,999999)}
{QC_6 = if(Q00_6=="Y",QC_6,999999)}
{QC_7 = if(Q00_7=="Y",QC_7,999999)}
{QC_8 = if(Q00_8=="Y",QC_8,999999)}
{QC_9 = if(Q00_9=="Y",QC_9,999999)}
{QC_10 = if(Q00_10=="Y",QC_10,999999)}
{QC_11 = if(Q00_11=="Y",QC_11,999999)}
{QC_12 = if(Q00_12=="Y",QC_12,999999)}
{QC_13 = if(Q00_13=="Y",QC_13,999999)}
{QC_14 = if(Q00_14=="Y",QC_14,999999)}
{QC_15 = if(Q00_15=="Y",QC_15,999999)}


The minimum if calculated
{QC_m1 = min(QC_1,QC_2,QC_3,QC_4,QC_5,QC_6,QC_7,QC_8,QC_9,QC_10,QC_11,QC_12,QC_13,QC_14,QC_15)}

The second, third,... minimums are calculated
{QC_m2 = min(if(QC_1==QC_m1,999999,QC_1), if(QC_2==QC_m1,999999,QC_2), if(QC_3==QC_m1,999999,QC_3), if(QC_4==QC_m1,999999,QC_4), if(QC_5==QC_m1,999999,QC_5), if(QC_6==QC_m1,999999,QC_6), if(QC_7==QC_m1,999999,QC_7), if(QC_8==QC_m1,999999,QC_8), if(QC_9==QC_m1,999999,QC_9), if(QC_10==QC_m1,999999,QC_10), if(QC_11==QC_m1,999999,QC_11), if(QC_12==QC_m1,999999,QC_12), if(QC_13==QC_m1,999999,QC_13), if(QC_14==QC_m1,999999,QC_14), if(QC_15==QC_m1,999999,QC_15))}{QC_m3 = min(if(QC_1<=QC_m2,999999,QC_1), if(QC_2<=QC_m2,999999,QC_2), if(QC_3<=QC_m2,999999,QC_3), if(QC_4<=QC_m2,999999,QC_4), if(QC_5<=QC_m2,999999,QC_5), if(QC_6<=QC_m2,999999,QC_6), if(QC_7<=QC_m2,999999,QC_7), if(QC_8<=QC_m2,999999,QC_8), if(QC_9<=QC_m2,999999,QC_9), if(QC_10<=QC_m2,999999,QC_10), if(QC_11<=QC_m2,999999,QC_11), if(QC_12<=QC_m2,999999,QC_12), if(QC_13<=QC_m2,999999,QC_13), if(QC_14<=QC_m2,999999,QC_14), if(QC_15<=QC_m2,999999,QC_15))}

m4 and m5 analogue.

Now we handle subquestion 5.
If it was selected the limit of the other subquestions is m4, otherwise m5
{QC_max = if(Q00_5=="Y", QC_m4, QC_m5)}

Now the subquestion relevance are quite short
Q00_1=="Y" AND QC_1 <= QC_max
Q00_2=="Y" AND QC_2 <= QC_max
...
Q00_5=="Y"
Q00_6=="Y" AND QC_6 <= QC_max

...

The second idea is similar, but instead of a long equation we move this to the subquestion relvance
Create a (hidden) question (QC) of type "multiple short text" with 15 subquestion (15 to store the random number - 1,2,3,...).
Create a (hidden) question of type equation with 

{QC_1 = if(is_empty(QC_1), rand(1,10000), QC_1)}
{QC_2 = if(is_empty(QC_2), rand(1,10000), QC_2)}
{QC_3 = if(is_empty(QC_3), rand(1,10000), QC_3)}
{QC_4 = if(is_empty(QC_4), rand(1,10000), QC_4)}
{QC_5 = 999999}
{QC_6 = if(is_empty(QC_6), rand(1,10000), QC_6)}
{QC_7 = if(is_empty(QC_7), rand(1,10000), QC_7)}
{QC_8 = if(is_empty(QC_8), rand(1,10000), QC_8)}
{QC_9 = if(is_empty(QC_9), rand(1,10000), QC_9)}
{QC_10 = if(is_empty(QC_10), rand(1,10000), QC_10)}
{QC_11 = if(is_empty(QC_11), rand(1,10000), QC_11)}
{QC_12 = if(is_empty(QC_12), rand(1,10000), QC_12)}
{QC_13 = if(is_empty(QC_13), rand(1,10000), QC_13)}
{QC_14 = if(is_empty(QC_14), rand(1,10000), QC_14)}
{QC_15 = if(is_empty(QC_15), rand(1,10000), QC_15)}


Now in the subquestion relevance enter
1: 
Q00_1=="Y" AND sum( intval(Q00_2=="Y" AND QC_2<QC_1), intval(Q00_3=="Y" AND QC_3<QC_1), intval(Q00_4=="Y" AND QC_4<QC_1), intval(Q00_5=="Y" AND QC_5<QC_1), intval(Q00_6=="Y" AND QC_6<QC_1), intval(Q00_7=="Y" AND QC_7<QC_1), intval(Q00_8=="Y" AND QC_8<QC_1), intval(Q00_9=="Y" AND QC_9<QC_1), intval(Q00_10=="Y" AND QC_10<QC_1), intval(Q00_11=="Y" AND QC_11<QC_1), intval(Q00_12=="Y" AND QC_12<QC_1), intval(Q00_13=="Y" AND QC_13<QC_1), intval(Q00_14=="Y" AND QC_14<QC_1), intval(Q00_15=="Y" AND QC_15<QC_1) )<5-intval(Q00_5=="Y")

2:
Q00_2=="Y" AND sum( intval(Q00_2=="Y" AND QC_1<QC_2), intval(Q00_3=="Y" AND QC_3<QC_2), intval(Q00_4=="Y" AND QC_4<QC_2), intval(Q00_5=="Y" AND QC_5<QC_2), intval(Q00_6=="Y" AND QC_6<QC_2), intval(Q00_7=="Y" AND QC_7<QC_2), intval(Q00_8=="Y" AND QC_8<QC_2), intval(Q00_9=="Y" AND QC_9<QC_2), intval(Q00_10=="Y" AND QC_10<QC_2), intval(Q00_11=="Y" AND QC_11<QC_2), intval(Q00_12=="Y" AND QC_12<QC_2), intval(Q00_13=="Y" AND QC_13<QC_2), intval(Q00_14=="Y" AND QC_14<QC_2), intval(Q00_15=="Y" AND QC_15<QC_2) )<5-intval(Q00_5=="Y")
...
5: 
Q00_5=="Y"

6:
Q00_6=="Y" AND sum(intval(Q00_6=="Y" AND QC_1<QC_6), intval(Q00_2=="Y" AND QC_2<QC_6), intval(Q00_3=="Y" AND QC_3<QC_6), intval(Q00_4=="Y" AND QC_4<QC_6), intval(Q00_5=="Y" AND QC_5<QC_6), intval(Q00_7=="Y" AND QC_7<QC_6), intval(Q00_8=="Y" AND QC_8<QC_6), intval(Q00_9=="Y" AND QC_9<QC_6), intval(Q00_10=="Y" AND QC_10<QC_6), intval(Q00_11=="Y" AND QC_11<QC_6), intval(Q00_12=="Y" AND QC_12<QC_6), intval(Q00_13=="Y" AND QC_13<QC_6), intval(Q00_14=="Y" AND QC_14<QC_6), intval(Q00_15=="Y" AND QC_15<QC_6) )<5-intval(Q00_5=="Y")
...

15:
Q00_15=="Y" AND sum(intval(Q00_15=="Y" AND QC_1<QC_15), intval(Q00_2=="Y" AND QC_2<QC_15), intval(Q00_3=="Y" AND QC_3<QC_15), intval(Q00_4=="Y" AND QC_4<QC_15), intval(Q00_5=="Y" AND QC_5<QC_15), intval(Q00_6=="Y" AND QC_6<QC_15), intval(Q00_7=="Y" AND QC_7<QC_15), intval(Q00_8=="Y" AND QC_8<QC_15), intval(Q00_9=="Y" AND QC_9<QC_15), intval(Q00_10=="Y" AND QC_10<QC_15), intval(Q00_11=="Y" AND QC_11<QC_15), intval(Q00_12=="Y" AND QC_12<QC_15), intval(Q00_13=="Y" AND QC_13<QC_15), intval(Q00_14=="Y" AND QC_14<QC_15) )<5-intval(Q00_5=="Y")

I am sure there are more approaches.
Use your imagination.

Joffm
 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 2 weeks 5 days ago by Joffm.

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose