- Posts: 10507
- Karma: 408
- Thank you received: 1864
- Forum
- English support forums
- Can I do this with LimeSurvey?
- Auto tick multiple choice answer based on a previous anwer
Auto tick multiple choice answer based on a previous anwer
- DenisChenu
-
- Away
- LimeSurvey Community Team
-
Thendevelnick wrote: Ok. And what happens if the user hits the "Previous" button? Is this code executed?
{q1_c=if(is_empty(q1_c.NAOK,if(q2_f=="Y", "Y",""),q1_c.NAOK)}
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .
Please Log in or Create an account to join the conversation.
The "previous" button is always ON, so the user can always change the answer.
And also, if I use at the same time
{q2_f=if(q1_c=="Y", "Y","")} for question q2_f
{q1_c=if(q2_f=="Y", "Y","")} for question q1_c
the link didn't work
- Nick
Please Log in or Create an account to join the conversation.
- DenisChenu
-
- Away
- LimeSurvey Community Team
-
- Posts: 10507
- Karma: 408
- Thank you received: 1864
Maybe better with
Create 2 equation question
First one : your equation : {q1_c=if(is_empty(isDone.NAOK),if(q2_f=="Y", "Y",""),q1_c.NAOK)}{q1_b=if(is_empty(isDone.NAOK),if(q2_g=="Y", "Y",""),q1_c.NAOK)}
Second one named isDone : equation 1
Else about : «it didn't work» : and ? Yes ? It diodn't work for you … but you don't give any information . For example a screenshot of the survey logic file ?
EDIT
{q2_f=if(q1_c=="Y", "Y","")}
{q1_c=if(q2_f=="Y", "Y","")}
I think in this condition : the equation are get in order.
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .
Please Log in or Create an account to join the conversation.
Let me clarify the behavior I would replicate.
I have this survey - you can see in the attachment - that makes it possible to go back and change the previous question, so the "back" and the menu button are enabled.
G1 is the first question group and contains a list of questions S
G2 is the second question group and contains a subset of S
G1 has two questions:
- G1Q1 (multiple-choice; )
- g1_autotick (equation; the code to to bind G1Q1 and G2Q1 )
- G1Q1 has three answers
- Document A
- Document B
- Document C
G2 has two questions:
- g2_autotick (equation; the code to bind G2Q1 and G1Q1)
- G2Q1 (multiple-choice)
- G2Q1 has three answers:
- Document D
- Document E
- Document C
Expected Behavior
Standard example:
If the User selects Document C from G1Q1, he will see Document C auto-selected in G2Q1.
If the User selects Document C from G2Q1, he will see Document C auto-selected in G1Q1, after hitting the previous button.
Another example:
If the User selects Document C from G1Q1 and de-selects document C from G2Q1, he will see Document C de-selected from G1Q1, after hitting the previous button.
If the User doesn't select Document C from G1Q1 and and selects Document C from G2Q1, he will see Document C auto-selected from G1Q1, after hitting the previous button.
Problems
I tried to use your code but it says "Missing close parenthesis"
Then I tried to re-factor the parenthesis, but it says "Function does not support too many arguments"
Then I re-interpreted your code and:
Then I tried to test the survey another time but:
See the video
The code from works however only one-way:
Document C of G1Q1---> Document C of G2Q1 (bind OK)
Document C of G1Q1 <--- Document C of G2Q1 (bind FAIL)
Document C of G1Q1 ---> Document C of G2Q1 (bind FAIL)
Document C of G1Q1 <--- Document C of G2Q1 (bind ok)
- Nick
Please Log in or Create an account to join the conversation.
- DenisChenu
-
- Away
- LimeSurvey Community Team
-
- Posts: 10507
- Karma: 408
- Thank you received: 1864
Maybe try
{q1_c=if(is_empty(isDone.NAOK),if(q2_f=="Y", "Y",""),q1_c.NAOK)}{q1_b=if(is_empty(isDone.NAOK),if(q2_g=="Y", "Y",""),q1_c.NAOK)}
No time currently to look at your survey.
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .
Please Log in or Create an account to join the conversation.
I don't understand where to put your code (I changed your variables with the survey's ones)
question code: "question1"
G1Q1_C=if(is_empty(isDone.NAOK), if(G2Q1_F == "Y", "Y", ""), G1Q1_C.NAOK)
question code: "isDone"
G2Q1_F=if(is_empty(isDone.NAOK), if(G1Q1_C == "Y", "Y", ""), G2Q1_F.NAOK)
I tried that but it works only one-way.
- Nick
Please Log in or Create an account to join the conversation.
- Nick
Please Log in or Create an account to join the conversation.
- DenisChenu
-
- Away
- LimeSurvey Community Team
-
- Posts: 10507
- Karma: 408
- Thank you received: 1864
Yes,develnick wrote: I tried that but it works only one-way.
I understand : but i don't understand what is your exact need …
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .
Please Log in or Create an account to join the conversation.
(this might be seen as a bug)
As a workaround -JavaScript!

Place a script like this in the source of the first question:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
var checkedState = false;
if('{G2Q1_F}' == 'Y') {
checkedState = true;
}
$('#answer{SGQ}C').prop('checked', checkedState).trigger('change');
});
</script>
And then something like this in the source of the second question:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
var checkedState = false;
if('{G1Q1_C}' == 'Y') {
checkedState = true;
}
$('#answer{SGQ}F').prop('checked', checkedState).trigger('change');
});
</script>
Sample survey attached:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Please Log in or Create an account to join the conversation.
- DenisChenu
-
- Away
- LimeSurvey Community Team
-
- Posts: 10507
- Karma: 408
- Thank you received: 1864
I'm unsuretpartner wrote: It seems that the two equations are fighting each other. I could not get it to work, even using simple equations that did not check for previous answers. If you use an equation to conditionally set Q1, you cannot use the value of Q1 in another conditional setting equation on the next page. It seems to return null.
(this might be seen as a bug)

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .
Please Log in or Create an account to join the conversation.
I'm unsure
, but i need a complet lss showing exact issue.
Here is a basic survey. The question value assignment does not work going forwards but does work going backwards.
Survey attached:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
Please Log in or Create an account to join the conversation.
- DenisChenu
-
- Away
- LimeSurvey Community Team
-
- Posts: 10507
- Karma: 408
- Thank you received: 1864
step1 (validation of current group) : 1st equation do Q1_SQ001= "" because Q1_SQ002 is empty
step2 (validation of next group) : 2nd equation do Q1_SQ002= "" because Q1_SQ001 is empty
Backward:
2nd equation didn't happen (we don't validate current group)
step2 (validation of previous group) : 1st equation do Q1_SQ001=Q1_SQ002 because Q1_SQ002 is empty *
I really think it's not an issue

And clearly :
step1 from forward happen
Possible solution : use more group ?
PS : i think usage of isDoneQ1 and isDoneQ2 can do the trick too.
PS2 : see wityh doneQ2 : partial fix. The issue is more «What is the condition to update (or not) Q1»
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .
Please Log in or Create an account to join the conversation.
Forward :
step1 (validation of current group) : 1st equation do Q1_SQ001= "" because Q1_SQ002 is empty
Yes, but that should (I think) happen on page load, not after I manually set Q1. I check the box so Q1_SQ001== "Y" and that should override the equation and let the second equation set Q2.
No?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Please Log in or Create an account to join the conversation.
- DenisChenu
-
- Away
- LimeSurvey Community Team
-
- Posts: 10507
- Karma: 408
- Thank you received: 1864
No,tpartner wrote: Yes, but that should (I think) happen on page load, not after I manually set Q1. I check the box so Q1_SQ001== "Y" and that should override the equation and let the second equation set Q2.
Equation is done on page load and at page validation (move next) , it's better like this (we have issue some year ago).
If you want not updated : i think you can use isDoneQ1 var to don't update current value.
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .
Please Log in or Create an account to join the conversation.
What happens if I have to bind a lot of questions, instad of copying and pasting the code for each question? Is there a way like that?
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
var checkedState = false;
if('{<ARRAY_OF_QUESTIONS>}' == 'Y') {
checkedState = true;
}
$('#answer{SGQ}<ARRAY_OF_QUESTIONS>).prop('checked', checkedState).trigger('change');
});
</script>
Example:
G1Q1
> A
> B
> C
...
Z
G2Q1
> A
> B
> C
...
> Z
Thanks!
- Nick
Please Log in or Create an account to join the conversation.