Welcome to the LimeSurvey Community Forum

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

Auto tick multiple choice answer based on a previous anwer

More
6 years 11 months ago #174654 by develnick
I'd like to auto-tick multiple-choice answer based on a previous answer.

For example

Question q1: Select your documents

> Subquestion a: Document A [ ]
> Subquestion b: Document B [ ]
> Subquestion c: Document C [X]

i.e. User selects Document C

Question q2: Select your documents

> Subquestion d: Document D
> Subquestion e: Document E
> Subquestion f: Document C [X]

i.e. User doens't need to select another time Document C, it is auto-selected.

I tried using relevance equation for Subquestion f as it follows:
Code:
!q1_c.NAOK

but this code only hide the question.

- Nick
The topic has been locked.
More
6 years 11 months ago #174657 by holch
The relevance equation is only there for hiding/showing questions.

What you will probably have to do is create a hidden equation type question, check if a subquestion has been checked and then mark it.

Probalby something like this (not tested, and you will of course have to make adaptation to fit for your survey):
Code:
{if(q1_c=="Y", q2_f="Y",)

Something like that.

Help us to help you!
  • Provide your LS version and where it is installed (own server, uni/employer, SaaS hosting, etc.).
  • Always provide a LSS file (not LSQ or LSG).
Note: I answer at this forum in my spare time, I'm not a LimeSurvey GmbH employee.
The topic has been locked.
More
6 years 11 months ago #174666 by DenisChenu

holch wrote: Probalby something like this (not tested, and you will of course have to make adaptation to fit for your survey):

Code:
{if(q1_c=="Y", q2_f="Y",)

Something like that.

No, it never work.

Asignation must be done like this:
{q2_f=if(q1_c=="Y", "Y","")}

{QuestionToAssign=ValueToSet}

Not in other way :)

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.
The topic has been locked.
More
6 years 11 months ago #174670 by holch

No, it never work.


I noticed that. I played around a little, and it did not work.

Thanks for skipping in and proposing the correct way.

Help us to help you!
  • Provide your LS version and where it is installed (own server, uni/employer, SaaS hosting, etc.).
  • Always provide a LSS file (not LSQ or LSG).
Note: I answer at this forum in my spare time, I'm not a LimeSurvey GmbH employee.
The topic has been locked.
More
6 years 11 months ago #174671 by DenisChenu

holch wrote: …

Thanks for skipping in and proposing the correct way.

Thanks to you for all community help you offer gracefully :)

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.
The topic has been locked.
More
6 years 11 months ago #174673 by holch
But somehow your solution didn't work for me either.

I assumed it works only if the second question is on a different page, but it didn't.

Do you see any errors?

Help us to help you!
  • Provide your LS version and where it is installed (own server, uni/employer, SaaS hosting, etc.).
  • Always provide a LSS file (not LSQ or LSG).
Note: I answer at this forum in my spare time, I'm not a LimeSurvey GmbH employee.
The topic has been locked.
More
6 years 11 months ago - 6 years 11 months ago #174675 by DenisChenu

holch wrote: …

I assumed it works only if the second question is on a different page, but it didn't.

Yes : assign action is done only with PHP, then when move next /previous

In same page : you can have a look at this old javascript code : demonstration.sondages.pro/676785?lang=fr

survey in french, but code is international ;)

MULTIPLE : updated via js (to trigger filter on FILTER and FILTEREXCLUDE)

MULTIPLE2 : updated via php (to trigger filter on FILTER2 and FILTEREXCLUDE2)

Think the system still work on 3.X.
If PHP system didn't work : it's a bug ;)

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.
Last edit: 6 years 11 months ago by DenisChenu.
The topic has been locked.
More
6 years 11 months ago #174677 by develnick
Hi Denis, thank you for your answer.

I'm using Version 3.14.10+180924. I tried your code this way

{q2_f=if(q1_c=="Y", "Y","")}

and I also tried

{q2_f=if(q1_c=="Y", "Y","N")}

However, it didn't work.

I also saw your demo here demonstration.sondages.pro/676785?lang=fr , however it seems this example is using array questions.

However, in my survey we are using simple multiple choice questions. Maybe that's the issue here.

- Nick
The topic has been locked.
More
6 years 11 months ago #174682 by tpartner
@develnick, your first equation is correct but the assignment needs to be done in an equation type question, not in a long-text as you have for "G1Q3".

Working sample survey attached:

File Attachment:

File Name: limesurvey...1541.lss
File Size:19.63 KB

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: DenisChenu, develnick
The topic has been locked.
More
6 years 11 months ago #174685 by holch
This was actually my example (thus my error!). I don't know how this could happen. Must have clicked wrong at one point. I even wondered what that stupid box was in the equation question...

I guess I know now. I need the weekend. ;-)

Tried to change it, but it won't change??? Strange. Need to check if this is a bug.

Help us to help you!
  • Provide your LS version and where it is installed (own server, uni/employer, SaaS hosting, etc.).
  • Always provide a LSS file (not LSQ or LSG).
Note: I answer at this forum in my spare time, I'm not a LimeSurvey GmbH employee.
The topic has been locked.
More
6 years 11 months ago #174686 by holch
Works! Thank you Tpartner for highlighting this stupid mistake with the wrong question type. I was looking and looking and looking and didn't see what was wrong with my code. Turns out: Nothing. :-)

Help us to help you!
  • Provide your LS version and where it is installed (own server, uni/employer, SaaS hosting, etc.).
  • Always provide a LSS file (not LSQ or LSG).
Note: I answer at this forum in my spare time, I'm not a LimeSurvey GmbH employee.
The topic has been locked.
More
6 years 10 months ago #174753 by develnick
Thanks, your explanation is great.
What about if the user wants to change also the Q1_c answer while choosing Q2_f i.e. one-to-one correspondence? For instance, imagine an user de-tick Q2_f. With your code, Q1_c is still selected.

Maybe I can try

{q1_c=if(q2_f=="Y", "Y","")} but where do I have to put that code?

- Nick
The topic has been locked.
More
6 years 10 months ago #174760 by tpartner
In an equation question in a group after the q2 group.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
6 years 10 months ago #174766 by develnick
Ok. And what happens if the user hits the "Previous" button? Is this code executed?

- Nick
The topic has been locked.
More
6 years 10 months ago #174780 by tpartner
Yes, it will be executed every time the page is visited. I assumed that with this type of value assignment that you had the Previous button disabled.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose