Welcome to the LimeSurvey Community Forum

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

Question text dependent on previous answer

  • tosa2021
  • tosa2021's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 9 months ago - 2 years 9 months ago #217555 by tosa2021
Hi all,

Wondering if Lime Survey can support question text that changes based on how someone answers an earlier question?

Simple example: a survey about pet ownership. We assume question 1 has mutually exclusive answers. Question 2's text then changes based on what you answered in question 1.
Q1) What kind of pet do you own?
A1) Dog
A2) Cat
A3) Fish

Q2) How old is your [dog/cat/fish]?
.. 

And so on.

In my actual survey, Q1 has six choices. It's a survey on caregiving. The goal is to avoid an awkward generic word or assumption and instead substitute in the actual relationship (parent, child, spouse, etc.).

I can think of two ways of achieving this:
1) Add custom languages and have question 1 be a "language" dropdown. Hide all other language dropdowns. A lot of work and I do not believe I have sufficient access to even achieve this (I'm in an enterprise environment and support from IT is minimal). Would give a clean data dump at the end.
2) Conditional logic. Somewhat labour-intensive but overall straightforward to implement (using a .csv editor to do find/replace en masse) and data cleanup wouldn't be too tedious (six sets of responses/questions).

Is there something smarter/quicker I can do?

I'm working with version 3.15.5+181115. As noted above, I am in an enterprise environment with some limited functionality. I cannot do any JavaScript in questions. I can edit themes/twig files, but don't believe I can get at the translation/language files.
Last edit: 2 years 9 months ago by tosa2021. Reason: weird formatting bug
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 9 months ago #217560 by holch
Replied by holch on topic Question text dependent on previous answer
You will just need to learn a little bit about expression manager/script.

Here the link to the manual: manual.limesurvey.org/Expression_Manager

Let's say your first question Q1 is single choice. If someone answers Dog, which is Answercode A1 you can show the given response anywhere in the survey (after Q1 of course!!!) with something like this:
Code:
{Q1.shown}

This is called micro tailoring. In your case it is pretty simple, because you could pipe in the word "Dog" just like it is.

But you can also create more complicated scenarios. E.g. if you only ask if a person is male or female, but later want to address them with Mr. or Mrs. Then you can use more complicated expressions to check if a person has answered male or female in a question and then adapting the text accordingly, for example like that:
Code:
{if(gender==1;"Mr.";"Mrs.")} {lastname}

(assuming that the gender was asked in a question called "gender" and the answer option "1" stands for male and answer option 2 stands for female and there is no other gender option. This is just an example.

And then you could pipe in the last name of the respondent as well.

Some further links to read through:
manual.limesurvey.org/ExpressionScript_How-tos
manual.limesurvey.org/ExpressionScript_examples

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The following user(s) said Thank You: DenisChenu, tosa2021
The topic has been locked.
  • tosa2021
  • tosa2021's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 9 months ago #217562 by tosa2021
Replied by tosa2021 on topic Question text dependent on previous answer
Perfect! That looks like exactly what I’m after. I’ll give it a try and chime in if I’m hitting any walls, but looks simple.

Thank you!!
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 9 months ago #217564 by holch
Replied by holch on topic Question text dependent on previous answer
Yes, it is actually pretty simple, fast and straightforward, once you get it. But should you have any more specific questions, just ask. Ideally providing a prototype with your question, which allows us to understand what you are doing and find potential errors.

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.
  • tosa2021
  • tosa2021's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 9 months ago #217565 by tosa2021
Replied by tosa2021 on topic Question text dependent on previous answer
Got it working exactly as needed. Just using some nested if statements to handle the various response options. Thanks for pointing me in the right direction!
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose