Welcome, Guest
Username: Password: Remember me

TOPIC: Show a different image in text depending on an answer to a previous question?

Show a different image in text depending on an answer to a previous question? 2 years 10 months ago #65638

  • KingKorn
  • KingKorn's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 26
  • Karma: 0
Hello,

I'd like to have a question, that shows an image embedded in the text. I would now like to show a different image depending on how a participant answered a previous question. Is that possible with script and if so how?

Thanks and best regards, kingkorn
The administrator has disabled public write access.

Re: Show a different image in text depending on an answer to a previous question? 2 years 10 months ago #65644

  • TMSWhite
  • TMSWhite's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 82
  • Karma: 36
This will be easy in LimeSurvey 1.92, regardless of whether you are pick from a handful or hundreds of possible images, since it supports Expressions.

Say you are picking from 4 pictures, and say your question Q1 could have answers A, B, C or D. You could put the following in the next question:
Here is a picture of your selection:  <img src="images/mine_{Q1}.png"/>

Or
Here is a picture of your selection: <img src="images/mine_{if(Q1=='A','first',if(Q1=='B','second',if(Q1=='C','third','fourth')))}.png">

For more complex choices, you would use an Equation question type first (called E1). Say you now have 3 questions, Q1-Q3, and each have answer options 1-5. That gives 125 possible combinations of pictures, so you could do this with E1:
implode('_','"images/mine',Q1,Q2,Q3,'.png"')

So, if your answers were 3, 4, 2, you would get "images/mine_3_4_2.png". Then, your question would be:
That combination of red, green, and blue yields the following color:  <img src={E1}>

The simple versions of this can also be done in LimeSurvey 1.91 - e.g. using {INSERTANS:xxxx} as long as you make sure that your image name matches the visible answer value for Q1.
Last Edit: 2 years 10 months ago by TMSWhite.
The administrator has disabled public write access.

Re: Show a different image in text depending on an answer to a previous question? 2 years 10 months ago #65646

  • KingKorn
  • KingKorn's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 26
  • Karma: 0
thanks, man - today you're my personal hero! :)
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.335 seconds
Donation Image