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

More
5 years 6 months ago - 5 years 6 months ago #77374 by BestUndecided
BestUndecided created the topic: Select an answer within a hidden question based on an Expression Manager formula
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: 5 years 6 months ago by BestUndecided.

Please Log in to join the conversation.

More
5 years 6 months ago #77376 by TMSWhite
TMSWhite replied the topic: Select an answer within a hidden question based on an Expression Manager formula
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)}

Please Log in to join the conversation.

More
5 years 6 months ago #77377 by BestUndecided
BestUndecided replied the topic: Select an answer within a hidden question based on an Expression Manager formula
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

Please Log in to join the conversation.

More
5 years 6 months ago #77461 by BestUndecided
BestUndecided replied the topic: Select an answer within a hidden question based on an Expression Manager formula
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!

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now