- Posts: 33
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
change icon depending on answer to previous question
- wilverley
- Topic Author
- Offline
- Junior Member
Less
More
8 years 6 months ago #127361
by wilverley
change icon depending on answer to previous question was created by wilverley
I have a survey which asks date of birth and gender, at the end I have a summery. I have an icon for male and female which changes dependent on if the respondent is male or female. I would also like the icon to change depending if the person is under or over the age of 16, so a child Icon will show for someone under 16 and an adult icon will show for someone over 16. I have included the survey so you can see what I am trying to achieve. Is anyone able to help solve this problem
Attachments:
The topic has been locked.
- holch
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 11660
- Thank you received: 2742
8 years 6 months ago #127362
by holch
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Replied by holch on topic change icon depending on answer to previous question
First of all you will need to understand a little bit about expression manager. Once you know about that, you would create a if loop to check if the person is male or female and the age is above or below 16. Depending on that you would call te respective image within a text display question.
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.
- wilverley
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 33
- Thank you received: 0
8 years 6 months ago #127363
by wilverley
Replied by wilverley on topic change icon depending on answer to previous question
yes I have gone through the expression manager notes but can not work out how to do it
The topic has been locked.
- holch
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 11660
- Thank you received: 2742
8 years 6 months ago #127367
by holch
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Replied by holch on topic change icon depending on answer to previous question
What did you try, where are you stuck?
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
The topic has been locked.
- wilverley
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 33
- Thank you received: 0
8 years 6 months ago - 8 years 6 months ago #127444
by wilverley
Replied by wilverley on topic change icon depending on answer to previous question
I have this which I have adapted from 2 other examples, if a person answers male/female then it inserts an adult male/female icon then gives their name and age. this works fine so I have tried to adapt it to give different icons depending on the age of the respondant
{if(p2sex=='M','','')} {INSERTANS:436365X532X2382SQ001_SQ001} {INSERTANS:436365X532X2382SQ001_SQ002} Age {floor((time() - mktime(0,0,0,substr(p2dob,5,2),substr(p2dob,8,2),substr(p2dob,0,4)))/(365.25*24*60*60))}
so in my (probably flawed) logic I thought I would need to get the age first and then the icon so I have
{if{floor((time() - mktime(0,0,0,substr(p2dob,5,2),substr(p2dob,8,2),substr(p2dob,0,4)))/(365.25*24*60*60))}>=17(p2sex=='M','','')} {INSERTANS:436365X532X2382SQ001_SQ001} {INSERTANS:436365X532X2382SQ001_SQ002} Age {floor((time() - mktime(0,0,0,substr(p2dob,5,2),substr(p2dob,8,2),substr(p2dob,0,4)))/(365.25*24*60*60))}
then
{if{floor((time() - mktime(0,0,0,substr(p2dob,5,2),substr(p2dob,8,2),substr(p2dob,0,4)))/(365.25*24*60*60))}<=16(p2sex=='M','','')} {INSERTANS:436365X532X2382SQ001_SQ001} {INSERTANS:436365X532X2382SQ001_SQ002} Age {floor((time() - mktime(0,0,0,substr(p2dob,5,2),substr(p2dob,8,2),substr(p2dob,0,4)))/(365.25*24*60*60))}
but I get an error on the "IF" it is red and so is the last } at the end of the the first floortime in each statement
hopefully this makes sense? any ideas what I have done wrong
{if(p2sex=='M','','')} {INSERTANS:436365X532X2382SQ001_SQ001} {INSERTANS:436365X532X2382SQ001_SQ002} Age {floor((time() - mktime(0,0,0,substr(p2dob,5,2),substr(p2dob,8,2),substr(p2dob,0,4)))/(365.25*24*60*60))}
so in my (probably flawed) logic I thought I would need to get the age first and then the icon so I have
{if{floor((time() - mktime(0,0,0,substr(p2dob,5,2),substr(p2dob,8,2),substr(p2dob,0,4)))/(365.25*24*60*60))}>=17(p2sex=='M','','')} {INSERTANS:436365X532X2382SQ001_SQ001} {INSERTANS:436365X532X2382SQ001_SQ002} Age {floor((time() - mktime(0,0,0,substr(p2dob,5,2),substr(p2dob,8,2),substr(p2dob,0,4)))/(365.25*24*60*60))}
then
{if{floor((time() - mktime(0,0,0,substr(p2dob,5,2),substr(p2dob,8,2),substr(p2dob,0,4)))/(365.25*24*60*60))}<=16(p2sex=='M','','')} {INSERTANS:436365X532X2382SQ001_SQ001} {INSERTANS:436365X532X2382SQ001_SQ002} Age {floor((time() - mktime(0,0,0,substr(p2dob,5,2),substr(p2dob,8,2),substr(p2dob,0,4)))/(365.25*24*60*60))}
but I get an error on the "IF" it is red and so is the last } at the end of the the first floortime in each statement
hopefully this makes sense? any ideas what I have done wrong
Last edit: 8 years 6 months ago by wilverley. Reason: trying to make the message clearer
The topic has been locked.
- holch
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 11660
- Thank you received: 2742
8 years 6 months ago #127456
by holch
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Replied by holch on topic change icon depending on answer to previous question
I am not too surprised that you get an error in your if loop. what it would currently do is to write a comma (",") when p2sex is "m". Not sure if this makes much sense.
I am also not sure why you mix question codes and SGQA codes. This is quite chaotic. I would first create an equation to write in the age. So you later only need to reference this equation question. There you could also see if the age is calculated correctly.
I am also not sure why you mix question codes and SGQA codes. This is quite chaotic. I would first create an equation to write in the age. So you later only need to reference this equation question. There you could also see if the age is calculated correctly.
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.
- wilverley
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 33
- Thank you received: 0
8 years 6 months ago - 8 years 6 months ago #127463
by wilverley
Replied by wilverley on topic change icon depending on answer to previous question
well actually no that is not the case the icons did not copy across
this bit
{if(p2sex=='M','male icon ','female icon')} inserts the correct male/female icon dependant on whether the person says they are male or female.
so I end up with this
All I am trying to do is change the icon according to the age and gender of the respondent, it seems like I am almost there but I am missing something.
this bit
{if(p2sex=='M','male icon ','female icon')} inserts the correct male/female icon dependant on whether the person says they are male or female.
so I end up with this
All I am trying to do is change the icon according to the age and gender of the respondent, it seems like I am almost there but I am missing something.
Attachments:
Last edit: 8 years 6 months ago by wilverley. Reason: add in clarity
The topic has been locked.
- holch
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 11660
- Thank you received: 2742
8 years 6 months ago #127469
by holch
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Replied by holch on topic change icon depending on answer to previous question
What about something like this:
However, I would still create an equation question first where you write in something like "young-female.jpg", "old-female.jpg", "young-male.jpg" or "old-male.jpg" depending on the age and gender question. Then in the actual report question you only need to reference this somehow. I think it is cleaner and you have the profile saved in a question. It is also easier to debug.
Code:
{if(p2sex=='M' && age<=16, 'male young icon', if(p2sex=='M' && age>16, 'male old icon', if(p2sex=='F' && age<=16, 'female young icon', 'female old icon') ) ) )}
However, I would still create an equation question first where you write in something like "young-female.jpg", "old-female.jpg", "young-male.jpg" or "old-male.jpg" depending on the age and gender question. Then in the actual report question you only need to reference this somehow. I think it is cleaner and you have the profile saved in a question. It is also easier to debug.
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.
- wilverley
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 33
- Thank you received: 0
8 years 6 months ago #127474
by wilverley
Replied by wilverley on topic change icon depending on answer to previous question
Thank you very much I will give that a try but I will take your advice and work on a better solution using an equation question.
The topic has been locked.