Welcome to the LimeSurvey Community Forum

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

Define a variable whose value depends on the answer to a previous question

  • lea_crtl
  • lea_crtl's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 months 2 weeks ago - 3 months 2 weeks ago #254195 by lea_crtl
LimeSurvey version: 3.24.3
==================
Good afternoon,

I would like to define a variable within my survey whose value depends on some previous answer (from a yes/no "Are you colorblind?" List (radio) question). I then need to use this variable to load different images, adapted to colorblind people or not.

Let's call the variable X and the previous question Q0.
I understand that X must be created using an "Equation type" question, but I don't know how to implement a condition within it.
From what I grasped I should write a basic equation like:
if(Q0 == "No", "standard_", "colorblind_") 

I would then like to use the variable X in a following question, to display different images depending on its value:
<img alt="" height="400" src="/upload/surveys/248689/images/{X}image.png" />

I tried this but it did not work. I don't know what I'm doing wrong. Maybe is "Q0" an inappropriate way to refer to this question in the equation formula? 

I checked the Expression Manager documentation here  manual.limesurvey.org/expression_Manager but could not find a way to do it.

Thank you very much for your help and I wish you a nice day, 

Léa
Last edit: 3 months 2 weeks ago by lea_crtl.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 months 2 weeks ago #254202 by Joffm
Hi,
you'd better send a lss export of these relevant questions.
But now we have to ask some questions:
1. What is the question code of the question of type "equation"?
2. What are the codes of the answer options in Q0?

Everything you show so far, can be correct.
So something seems to be wrong in the coding.
Did you read this?
[url] manual.limesurvey.org/ExpressionScript_-...#Access_to_variables [/url]
and did you activate the survey, enter some data and checked the response table?

Joffm

 

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

Please Log in to join the conversation.

  • lea_crtl
  • lea_crtl's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 months 2 weeks ago #254203 by lea_crtl
Thank you very much for your help. I can feel I'm getting close to solving my issue.
In my survey the Q0 question is called "daltonisme" and the answer to it is either "Oui" or "Non".
The X variable is called "typecartes". I defined it with the following equation:
{if(daltonisme == 'Non', 'std_', 'cb_')}
The problem is that whatever the answer to the "daltonisme" is, typecartes' value is always "cb_".
I activated the survey and checked that daltonisme's and typecartes' values appear.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 months 2 weeks ago #254204 by Joffm
Hi,
so your question "daltonisme" has the following anser options and codes?
 

I do not really believe this.

Therefore I wrote "Activate the survey, enter some data and check the responses table.

And send your lss export.

Joffm

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

Please Log in to join the conversation.

  • lea_crtl
  • lea_crtl's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 months 2 weeks ago - 3 months 2 weeks ago #254222 by lea_crtl
You're right, my question codes are A1 and A2... I changed the equation from {if(daltonisme == 'Non', 'std_', 'cb_')} to {if(daltonisme == 'A2', 'std_', 'cb_')} and now the typecartes variable takes the right value. But I'm still unable to load an image using this variable...
My script is:
<script>
<img alt="" height="400" src="/upload/surveys/248689/images/{typecartes}phase1_11.png" />
</script>

EDIT
: I figured out that I don't need to use the <script> flare since this is html code and no JS... Sorry for this beginner mistake and thanks a lot for your help. Everything works smoothly now.
Last edit: 3 months 2 weeks ago by lea_crtl.

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose