- Posts: 3
- Thank you received: 0
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
- Topic Author
- Offline
- New Member
Less
More
5 years 4 months ago #178205
by FRGDan
Dynamically show image based on previous responses was created 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:
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13637
- Thank you received: 2491
5 years 4 months ago #178210
by DenisChenu
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.
Replied by DenisChenu on topic Dynamically show image based on previous responses
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
- Topic Author
- Offline
- New Member
Less
More
- Posts: 3
- Thank you received: 0
5 years 4 months ago - 5 years 4 months ago #178226
by FRGDan
Replied by FRGDan on topic Dynamically show image based on previous responses
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.
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")
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10108
- Thank you received: 3593
5 years 4 months ago #178231
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Dynamically show image based on previous responses
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13637
- Thank you received: 2491
5 years 4 months ago #178237
by DenisChenu
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.
Replied by DenisChenu on topic Dynamically show image based on previous responses
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
- Topic Author
- Offline
- New Member
Less
More
- Posts: 3
- Thank you received: 0
5 years 4 months ago #178244
by FRGDan
Replied by FRGDan on topic Dynamically show image based on previous responses
I used single quote on my original, but didn't spot on your one too haha
The topic has been locked.