# conditions...

5 years 8 months ago - 5 years 8 months ago #62594
Hello,

I need help for a survey I am building. So far everything looks fine but the problem begins with conditions:

I have a list of 20 questions, that can all be answered "1", "2" or "3".

Depending on the answers to the first two questions I want this:

3 - 19, that can also be asnwered "1", "2" or "3"

So far everything is fine, I make a rule for question 3, so it will only show if 1 and 2 are answered "3", then copy that rule to q4 - q19.

Now to the tricky part:

Depending on the answers to the questions 3 - 9 I want the questions 10 - 19 to display, but:

Only If at least 5 of the questions 3 - 9 are answered "3" I want to display the questions 10 - 19.

How do I write those rules?

It looks VERY complicated to write down all possibilities:

if q3 = "3"
and
if q4 = "3"
and
if q5 = "3"
and
if q6 = "3"
and
if q7 = "3"

or

if q3 = "3"
and
if q4 = "3"
and
if q5 = "3"
and
if q6 = "3"
and
if q8 = "3"

or

if q3 = "3"
and
if q4 = "3"
and
if q5 = "3"
and
if q6 = "3"
and
if q9 = "3"

or

if q3 = "3"
and
if q4 = "3"
and
if q5 = "3"
and
if q7 = "3"
and
if q8 = "3"

if q3 = "3"
and
if q4 = "3"
and
if q5 = "3"
and
if q7 = "3"
and
if q9 = "3"

if q3 = "3"
and
if q4 = "3"
and
if q5 = "3"
and
if q6 = "3"
and
if q7 = "3"

if q3 = "3"
and
if q4 = "3"
and
if q6 = "3"
and
if q7 = "3"
and
if q8 = "3"

if q3 = "3"
and
if q4 = "3"
and
if q6 = "3"
and
if q7 = "3"
and
if q9 = "3"

and so on .....

How do I achieve this?

Thanks,
best regards

claudio

... lost in brackets ...
(I suggest a preview option for posting in the forum)
Last Edit: 5 years 8 months ago by claudio123.

5 years 8 months ago #62615 by Zappes
Hey Claudio,
instead of writing conditions you could try this by programming rules in javacript. works much easier.

5 years 8 months ago #62622
Using javascript will however ask for a new page, I think.

And how do I translate this in Java?

"Only show this question (and the next ones...) if at least 5 out of the questions 3 - 9 are answered '3' "

I am currently investigating a java script that checked the answers to an array, so maybe I find an answer there, but I stll have to get used to java's language of mathematics...

Thanks + best regards!

Claudio

... lost in brackets ...
(I suggest a preview option for posting in the forum)

5 years 8 months ago #62626 by TMSWhite
Claudio-

Another option we're exploring via a new, optional, Relevance functionality ( issue 5269 ), would let you set this as the condition:

count(q3==3,q4==3,q5==3,q6==3,q7==3,q8==3,q9==3) >= 5

You'd apply that condition to each of the questions q10-q19 (of if they are all in the same group, you can just apply that condition to the group), and it will ensure that questions 10-19 are only displayed if at least 5 of q3-q9 were answered 3.

-Tom
The following user(s) said Thank You: claudio123

5 years 8 months ago - 5 years 8 months ago #62627
Tom,

this is exactly what I was looking for - is there any possibility to have this as an addon or implemented on my install now?
I'm on Version 1.91+ Build 10315 and not too familiar with limesurvey. I have it installed two days ago locally on a virtual machine (virtualbox) using turnkey linux and managed to update to this latest version from a Version 1.8(?).

Thanks again for showing me this possibility that I now not only want but NEED )

best regards

Claudio

... lost in brackets ...
(I suggest a preview option for posting in the forum)
Last Edit: 5 years 8 months ago by claudio123. Reason: typo

5 years 7 months ago #62633 by TMSWhite
Claudio-

Glad to hear this is of potential value.

The ExpressionManager is operational (it can process the count(q3==3, ...) expression and give the right answer) - see patch for issue 5268 . However, it isn't integrated with conditions yet. That's one of my next tasks and I hope to be done in a few weeks.

/Tom

5 years 7 months ago #62635
- the show/hide solution shown in this thread by Tony (tpartner) might show a workaround that might allow conditional branching based on your Expression Manager (solving more complex mathematical challenges).

I'll have a look and try to patch my limesurvey install.

Thanks and best regards

Claudio

... lost in brackets ...
(I suggest a preview option for posting in the forum)

5 years 7 months ago #62642
Well, the patch did not work

root@lamp:/var/www# patch -p0 --dry-run < issue*
(Stripping trailing CRs from patch.)
(Stripping trailing CRs from patch.)
(Stripping trailing CRs from patch.)
patching file classes/dTexts/dTexts.php
Hunk #1 FAILED at 12.
1 out of 1 hunk FAILED -- saving rejects to file classes/dTexts/dTexts.php.rej
(Stripping trailing CRs from patch.)
patching file classes/eval/ExpressionManager.php
(Stripping trailing CRs from patch.)
patching file classes/eval/LimeExpressionManager.php
(Stripping trailing CRs from patch.)
patching file classes/eval/Test_ExpressionManager_Evaluate.php
(Stripping trailing CRs from patch.)
patching file classes/eval/Test_ExpressionManager_ProcessStringContainingExpressions.php
(Stripping trailing CRs from patch.)
patching file classes/eval/Test_ExpressionManager_Tokenizer.php
(Stripping trailing CRs from patch.)
patching file common_functions.php
(Stripping trailing CRs from patch.)
Hunk #1 FAILED at 278.
1 out of 1 hunk FAILED -- saving rejects to file printanswers.php.rej
(Stripping trailing CRs from patch.)
patching file save.php

looks like there is some more work to be done for me ...

regards
Claudio

... lost in brackets ...
(I suggest a preview option for posting in the forum)

5 years 7 months ago #62646 by tpartner
claudio123, are all questions on the same page? Or at least Q3-Q9?

If so we can use JavaScript to put a listener on them and populate a hidden question if at least 5 of them are answered "3".

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

5 years 7 months ago - 5 years 7 months ago #62648
Yes, I want all of them on the same page, I even think about putting them all in an array, but that should not make a big difference.
I tried your solution from here (..forum/can-i-do-this-with-limesurvey/58002-using-previous-array-question-responses-to-set-following-array-subquestions) but I also failed. :-S
I'd like to send you a tiny survey with your solution form that thread that is not fully functional..
Thanks and best regards
Claudio

... lost in brackets ...
(I suggest a preview option for posting in the forum)
Last Edit: 5 years 7 months ago by claudio123.

5 years 7 months ago #62649 by TMSWhite
Claudio-

For the short term, you might want to go with Tony's strategy. I can build a new patch, but until this functionality is added as official part of a LimeSurvey release, your LimeSurvey deployment would be brittle (e.g. that patch worked for me a couple of weeks ago, but the code base has already changed - if you use a new patch, you'd lock yourself of bugfix enhancements, or else I'd need to keep posting patches for each 1.91+ release).

/Tom

5 years 7 months ago - 5 years 7 months ago #62651
Tom,
thanks for your explanation, I think I'll go with tony's strategy, yes.

Tony,
attached you can find a javascript-free version of a mini survey I'd like to have enhanced with your help, if you allow me to ask for it.

Thanks + best regards
Claudio

#### File Attachment:

File Name: limesurvey...le-2.lss
File Size:48 KB

... lost in brackets ...
(I suggest a preview option for posting in the forum)
##### Attachments:
Last Edit: 5 years 7 months ago by claudio123.