Insert text depended on previous answer

More
5 months 3 weeks ago #152735 by SurveyDennis
SurveyDennis created the topic: Insert text depended on previous answer
I would like to show a different text/image depended on a previous answer.


I am trying to do this with JS but not getting it correctly.
I tried it with EM but not totally understanding how I could do this.

Anyone an idea.


The example I have now is:

<script type="text/javascript" charset="utf-8">
$(document).ready(function() {

if($('#answer279829X201X799SQ001').attr('checked', true)) { alert ('yes 1 checked'); };
if($('#answer279829X201X799SQ002').attr('checked', true)) { alert ('yes 2 checked'); };

});
</script>

Be SurveyFriendly too
SurveyFriendly Designer [at] SurveyFriendly [dot] com

Please Log in to join the conversation.

More
5 months 3 weeks ago #152736 by holch
holch replied the topic: Insert text depended on previous answer
I can't help with Javascript, but with EM this should be fairly easy.
What type of question do you use? For a single choice question for example you could do comething like this:
{if(Q1==1, "<img src='imageurl/img01.jpg' />", if(Q2==2, ""<img src='imageurl/img02.jpg' />","")}

Not tested.

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

Please Log in to join the conversation.

More
5 months 3 weeks ago #152737 by SurveyDennis
SurveyDennis replied the topic: Insert text depended on previous answer
Thanks, I tried this with EM but can I just add that in the question text? instead of the relevance eq.?

My question label is Q1 and my answer options are SQ001 and SQ002.
If I try it this way I only see the code itself in the question.



Be SurveyFriendly too
SurveyFriendly Designer [at] SurveyFriendly [dot] com
Attachments:

Please Log in to join the conversation.

More
5 months 3 weeks ago - 5 months 3 weeks ago #152738 by holch
holch replied the topic: Insert text depended on previous answer
You can use EM almost anywhere (answer options, subquestions, question text, etc.).

This is why I asked you in my previous response which question type you are using, because it is different on how you access it.

Seeing that you are using SQ001 etc., I assume that you use a question type that has subquestions (multiple answers, array).

In this case you need to proceed a little different. Would you mind sharing the question itself and what you are trying to show and when? Because multiple choice are different to matrix/array questions. E.g. for multiple choice you would probably need something like Q1_SQ001=="Y" to check if the check box has been checked, while for array questions you usually have various codes that could apply, e.g. Q1_SQ001 >= 4.

If you can provide these two questions in a LSS or LSG file, I can have a look at it. It is very simple with EM, but you need to know the structure of the questions to be able to check those things.

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds
Last Edit: 5 months 3 weeks ago by holch.

Please Log in to join the conversation.

More
5 months 3 weeks ago - 5 months 3 weeks ago #152739 by SurveyDennis
SurveyDennis replied the topic: Insert text depended on previous answer
Thanks for your detailed information.
Sorry my mistake with the multi response question.
It had to be a single response instead.

I have setup an example here:
www.surveyfriendly.com/ls1/index.php/sur...67/newtest/Y/lang/en

Q1 - Brand?
A1 Brand1
A2 Brand2
A3 Brand3

Depended on the brand I want to add an additional text.
For example
Brand 1 is only available in the color blue, etc.

I think it is just something on my syntax, I have now;

{if(Q1==A1, "Blue", if(Q1==A2, "Red", if(Q1==A3, "Yellow")}

Be SurveyFriendly too
SurveyFriendly Designer [at] SurveyFriendly [dot] com
Last Edit: 5 months 3 weeks ago by SurveyDennis.

Please Log in to join the conversation.

More
5 months 3 weeks ago - 5 months 3 weeks ago #152740 by holch
holch replied the topic: Insert text depended on previous answer
OK, I rebuilt your scenario to be able to test it and there are various problems in your code (that is why I asked for an export, I could have just imported your example and worked on it, without building my own one):
- There were missing a few ")" to close the IFs
- If you have answer codes that have a letter I think you need to put them into parentesis.
- It seems to be necessary to have something in the "else" part, and if it is just an empty string ("").

When you save and close the question, you can usually see your equation and if there is something wrong, LS gives you pretty good indications what is wrong (just hover over the errors with your mouse). For example without the "" the A1 was considered an undefined variable, so you know that EM doesn't recognize it. That helped me to notice that it needs to be "A1", not A1.
Please find a working sample attached to this post.

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds
Attachments:
Last Edit: 5 months 3 weeks ago by holch.
The following user(s) said Thank You: SurveyDennis

Please Log in to join the conversation.

More
5 months 3 weeks ago #152745 by SurveyDennis
SurveyDennis replied the topic: Insert text depended on previous answer
Sorry about that - I indeed could attach the survey.
Many thanks for your effort to rebuild it.
I see now where I missed the extra quotes.

Very powerfull this EM, just starting to play around with this!

Be SurveyFriendly too
SurveyFriendly Designer [at] SurveyFriendly [dot] com

Please Log in to join the conversation.

More
5 months 3 weeks ago #152746 by holch
holch replied the topic: Insert text depended on previous answer
No problem. I know that you give back to the community, so it is a pleasure to help.

Yes, EM is very powerful and really helped LS to progress. You can do a lot of things with EM, besides relevance equations (which are so much quicker and more flexible than conditions).

Have a look at the manual, there are very interesting examples that can give you inspiration. But I feel like today there are already so more examples of great use of EM that the examples in the manual look 'basic'.

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

Please Log in to join the conversation.

More
5 months 3 weeks ago #152753 by SurveyDennis
SurveyDennis replied the topic: Insert text depended on previous answer
Thank you for the kind words.
I am documenting all my examples and will share them soon as well to all Limesurvey users.

I will look at the EM manual and examples.

Be SurveyFriendly too
SurveyFriendly Designer [at] SurveyFriendly [dot] com

Please Log in to join the conversation.

More
5 months 3 weeks ago #153012 by SurveyDennis
SurveyDennis replied the topic: Insert text depended on previous answer
Sorry just on more question.
Seems I can't use html tags in there?

{if(PATRAN2 == 'A1', "<button class='btn btn-info btn-smg' data-target='#myModal1' data-toggle='modal' type='button'>Haga clic aquí para ampliar</button>", " ")}

Or do I need to define this different?

Be SurveyFriendly too
SurveyFriendly Designer [at] SurveyFriendly [dot] com

Please Log in to join the conversation.

More
5 months 3 weeks ago #153018 by holch
holch replied the topic: Insert text depended on previous answer
I am not sure, but I think the html tags need to be masked. I think tpartner posted an example a while ago. But I am not sure about this.

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now