Welcome, Guest
Username: Password: Remember me

TOPIC: Select an answer within a hidden question based on an Expression Manager formula

Select an answer within a hidden question based on an Expression Manager formula 2 years 6 months ago #77374

1) Is it possible to set a formula in each Answer Option, where if the conditions are met, that answer is selected?

2) Furthermore, is it possible to ask if a previous answer was selected without testing for value, or rather only testing for true/false rather than
if(a1 = "I chose this answer.") //a1 is answer code
So to sum that up; if an answer is selected, is there a value such as 'true' associated with that answer code? If so what is that value?
Last Edit: 2 years 6 months ago by BestUndecided.
The administrator has disabled public write access.

Re: Select an answer within a hidden question based on an Expression Manager formula 2 years 6 months ago #77376

  • TMSWhite
  • TMSWhite's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 82
  • Karma: 36
Can you be a little more specific?

(1) Do you mean conditionally set a default value? If so, sort of - you can use an Expression to set a default value for most question types that allow default values.

(2) To see whether there was an answer for a prior question, you could use {!is_empty(q1)}. To get the assessment value, code, or answer text for the selected value, use {qcode.value}, {qcode.code}, and {qcode.shown}, respectively. If you are trying to make a list of just the answered questions, you can do something like this {list(q1.shown, q2.shown, ..., q10.shown)}
The administrator has disabled public write access.

Re: Select an answer within a hidden question based on an Expression Manager formula 2 years 6 months ago #77377

1) If setting a default value works that is fine. I just need an answer selected in a List(radio) which affects my assessment score based on answers to previous questions.

2) All of my questions are mandatory, and I know how many questions were answered. I have 4 answer types for each question, but the answer type is not stated.
for instance below is question code = answer option:
Q1P = You like dogs
Q1N = Fall
Q2P = Have a great day
Q2N = What is your name
Q3P = Yahoooooooo
Q3N = I love bob

So would I be able to create 4 place holder variables that would just count the number of times the assessment code equals the value I test it against.

I would do this in the question
pcount = 0
if {q1.code} == Q1P;   //check if the first question resulted in a P answer
(pcount = pcount + 1)  //If yes add a 1 to the count of p value
if{q2.code} == Q2P;  
(pcount = pcount + 1)
if{q3.code} == Q3P;
(pcount =pcount + 1)
 
//lots o math to calculate which count is the max
//output max and second most

Then in each answer
if VALUE SAVE FROM QUESTION = pmaxnsecond;
make this answer default
The administrator has disabled public write access.

Re: Select an answer within a hidden question based on an Expression Manager formula 2 years 6 months ago #77461

I have placed the code below in a hidden equation question. I would like to then select a default answer based on the TOKEN:Max.

How do I create a default answer based on a token?
How do I test my code to see if it works?
{
TOKEN:max
TOKEN:second
TOKEN:ptotal
ptotal = 0
TOKEN:etotal
etotal = 0
TOKEN:ntotal
ntotal = 0
TOKEN:gtotal
gtotal = 0
if(Q1.code == Q1P,
  ptotal = ptotal+1,
  if(Q1.code == Q1E,
    etotal = etotal+1,
    if(Q1.code == Q1N,
      ntotal = ntotal +1,
        if(Q1.code==Q1G,
          gtotal = gtotal+1,
        )
      )
    )
  )
iif(Q2.code == Q2P,
  ptotal = ptotal+1,
  if(Q2.code == Q2E,
    etotal = etotal+1,
    if(Q2.code == Q2N,
      ntotal = ntotal +1,
        if(Q2.code==Q2G,
          gtotal = gtotal+1,
        )
      )
    )
  )
if(Q3.code == Q3P,
  ptotal = ptotal+1,
  if(Q3.code == Q3E,
    etotal = etotal+1,
    if(Q3.code == Q3N,
      ntotal = ntotal +1,
        if(Q3.code==Q3G,
          gtotal = gtotal+1,
        )
      )
    )
  )
if(ptotal > ntotal && ptotal > etotal && ptotal > gtotal,
  max = 'P'
  if(ntotal > ptotal && ntotal > etotal && ntotal > gtotal,
    max = 'N',
    if(etotal > ptotal && etotal > ntotal && etotal > gtotal,
      max = 'E',
      if(gtotal > ptotal && gtotal > etotal && gtotal > ntotal,
        max = 'G'
        )
      )
    )
  )
}

I would still have to make it far more extensive to cover 18 questions, and the 37 possible Max, Second combinations. But I first wanted to check if I am going about it the right way.

All help is greatly appreciated!
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.318 seconds
Donation Image