Welcome to the LimeSurvey Community Forum

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

Dynamically show image based on previous responses

  • FRGDan
  • FRGDan's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
5 years 4 months ago #178205 by FRGDan
Hi guys,

I'm wondering if something like this is possible (out of curiosity)

I have a Question with 5 options, and in a later question, I wish to show the corresponding image to the option that was selected.

E.g.:

Q1. Select one:
1
2
3 <- selected
4
5


Text Display: [Image 3 shown here]


Now.. The obvious solution to this? Just have 5x Text Display and use normal conditional routing. But I'm wondering, can I achieve the same result with expression manager?

I imagined something like this, however this will cause errors:
Code:
{if(Q1.NAOK == 1,
"<img src='https://via.placeholder.com/500x90.png?text=Image+1' />,
  if(Q1.NAOK == 2,
  "<img src='https://via.placeholder.com/500x90.png?text=Image+2' />,
    if(Q1.NAOK == 3,
    "<img src='https://via.placeholder.com/500x90.png?text=Image+3' />,
      if(Q1.NAOK == 4,
      "<img src='https://via.placeholder.com/500x90.png?text=Image+4' />,
        if(Q1.NAOK == 5,
        "<img src='https://via.placeholder.com/500x90.png?text=Image+5' />,
        ""
        )
      )
    )
  )
)}
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 4 months ago #178210 by DenisChenu
More simple to undetsrand and update (in yours : you didn't close the " in first item (maybe elseware))
Code:
{if(Q1.NAOK == 1,"<img src='https://via.example.com/500x90.png?text=Image+1' />","")}
{if(Q1.NAOK == 2,"<img src='https://via.example.com/500x90.png?text=Image+2' />","")}

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
  • FRGDan
  • FRGDan's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
5 years 4 months ago - 5 years 4 months ago #178226 by FRGDan
Hi Denis, apologies for the typo, I wrote that quickly as an example (the actual code needed to be written in a cascading style due to its complexity and need for prioritisation) :)

When I mean it wouldn't work like that - the same would occur in your example.

E.g.
Code:
<p>Only the image selected in Q1 should be shown here:</p>
 
{if(Q1.NAOK == 1,"<img src="https://via.placeholder.com/500x90.png?text=Image+1" />","")}
{if(Q1.NAOK == 2,"<img src="https://via.placeholder.com/500x90.png?text=Image+2" />","")}

Will break the expression and show something like this on screen:



(If I right click on the images and open as new tab, the URL contains html code pertaining to "Undefined Syntax" and "Undefined Variable")
Last edit: 5 years 4 months ago by FRGDan.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 4 months ago #178231 by tpartner
It may be due to double-quotes inside double-quotes.

Code:
<p>Only the image selected in Q1 should be shown here:</p>
 
{if(Q1.NAOK == 1,"<img src='https://via.placeholder.com/500x90.png?text=Image+1' />","")}
{if(Q1.NAOK == 2,"<img src='https://via.placeholder.com/500x90.png?text=Image+2' />","")}

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: FRGDan
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 4 months ago #178237 by DenisChenu
Yes, and i use simple quote for img src … bad copying

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
  • FRGDan
  • FRGDan's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
5 years 4 months ago #178244 by FRGDan
I used single quote on my original, but didn't spot on your one too haha
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose