Welcome to the LimeSurvey Community Forum

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

Color text based on assessement value

  • larseman
  • larseman's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 4 months ago #156319 by larseman
Color text based on assessement value was created by larseman
Hi

I am setting up Limesurvey for a quiz using assessements. Each question has five answers (radiobuttons) with one correct answer. The correct answer has a assessement value of 1, all the others 0.
I have a question at the end summing up the result:

Your result: {sum(Q1.value, Q2.value, Q3.value)}
Would you like to see the correct answers?

In the next "question" I'd like to show the correct answer together with the respondents answer. I would also like to color the respondents answer green if it was correct and red if it was wrong. Is this possible? I've been searching the forum but haven't found anything on the topic. I've also tried some coding with htmlentities() but my experience with LimeSurvey isn't good enough to succeed.

The question would go something like this:


Correct answers:

Question 1: What is...

Correct answer: It's a... (Is there a way to get the answer with a specific index with EM?)

Your answer: {if(Q1.value = 1, text in green, text in red


This is where I'm stuck. Any help appreciated, just point me in the right direction :-)
The topic has been locked.
More
7 years 4 months ago #156322 by Ben_V
Replied by Ben_V on topic Color text based on assessement value
Hi,
you can try something around:
Code:
{if(Q1.value == 1,'<font color=limegreen>green</font> ','<font color=red>red</font>')}

Benoît

EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
The following user(s) said Thank You: larseman
The topic has been locked.
  • larseman
  • larseman's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 4 months ago #156334 by larseman
Replied by larseman on topic Color text based on assessement value
Thanks a lot @Ben_V

I also figured out (by myself) how to insert the actual answer in the code:


{if(Q1.value == 1,'<font color=green>{Q1.shown}</font> ','<font color=red>{Q1.shown}</font>')}


So now it works exactly as I want it to :)

Next step is to learn how to use the forum in the right way with code examples in a box etc. :unsure:
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose