Welcome to the LimeSurvey Community Forum

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

Select answer in Q2 based on answer in Q1

  • JasonZA
  • JasonZA's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 6 months ago #207068 by JasonZA
Good day. I have now spent hours trying to do something that is probably pretty basic.


I would like to auto select an answer in a hidden radio box in Q8, based on a specific answer given in Q7. I have tried many combinations but cannot get this to work. Any assistance will be very much appreciated. Below is what I have tried (loosely based on another thread in the forum):


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

$('#question{QID}').hide();

if(Question07_SQ002 = Y) {
$('#question{QID} input.radio:eq(1)').trigger('click');
}
else {
$('#question{QID} input.radio:eq(0)').trigger('click');
}
});
</script>
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 6 months ago #207090 by holch
Replied by holch on topic Select answer in Q2 based on answer in Q1
If the question is hidden via GUI ("always hide this question") you can not update the question via Javascript, because the question is not visible for Javascript.

Then you have two options:
1. you hide the question via CSS, then you can update it via Javascript
2. you update the hidden question not via Javascript, but via Expression, that should work even if the question is "always hidden" via GUI.

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.
  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 6 months ago #207097 by Joffm
Replied by Joffm on topic Select answer in Q2 based on answer in Q1
Use Expression Manager.
Q7

eqQ8 (Equation) with (just an example, we don't konow how exactly you want to set the value of Q8)
{Q8=if(Q7_SQ002=="Y",1,"")}

Q8 ("always hide this question")
Now the value of Q8 is 1, if Q7_SQ002 was selected, else empty.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: DenisChenu, JasonZA
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 6 months ago #207113 by Joffm
Replied by Joffm on topic Select answer in Q2 based on answer in Q1
And, to add.
If Q8 is always hidden, you don't need it, you might use only the equation.
It stores the same value as Q8 and you can use it later as if it was a normal question.

As I said: without the exact scenario no more.

JOffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: JasonZA
The topic has been locked.
  • JasonZA
  • JasonZA's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 6 months ago #207115 by JasonZA
Replied by JasonZA on topic Select answer in Q2 based on answer in Q1
Many thanks @Joffm for the prompt reply. If the second answer option of Question 7 (which is a multi-choice question) is selected, then I want Question 8 (which is a radio question) to be answered "Yes" (first answer option) and if it is not selected, then I want it to be answered "No" (second answer option). I did not select the question to be hidden in the options for Question 8 - I only inserted this code into the question box: $('#question{QID}').hide();

The details below in line one is what I'm struggling to get right:

if(Question07_SQ002 = Y) {
$('#question{QID} input.radio:eq(0)').trigger('click');
}
else {
$('#question{QID} input.radio:eq(1)').trigger('click');
}

The snippet you sent makes sense but I'm not sure how to implement it into the question box, like I usually do with the java snippets I find online.

Kind Regards,
Jason
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 6 months ago #207119 by holch
Replied by holch on topic Select answer in Q2 based on answer in Q1
What Joffm is trying to say:

If the question 8 is hidden anyway, why even bother? You can just write the "yes" or "no" into an equation question (or the respective code).

Now if you insist to have this question as a "list (radio)" but hidden, you can just add an equation question and put Joffm's code in. This will mark the answer in the hidden Q8 based on the answers in Q7. I would always use Expressions where possible. Javascript only where Expressions won't work.

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.
  • JasonZA
  • JasonZA's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 6 months ago #207123 by JasonZA
Replied by JasonZA on topic Select answer in Q2 based on answer in Q1
Thanks a lot for the reply. I had a quota set up where only 15 respondents should answer selection 2 of Question 7 and a quota where the remaining answer options for Question 7 must add up to 15. Just thought that having a scenario like the one above would have made the quota easier to structure, as I could then link 15 quotas to a "Yes" in question 8 and the remaining 15 quotas to a "No" in question 8. This was the reason for me posting the question. I tried the equation question, based on a thread I read in the forum, but it didn't show up in the quotas.
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 6 months ago #207124 by holch
Replied by holch on topic Select answer in Q2 based on answer in Q1

I tried the equation question, based on a thread I read in the forum, but it didn't show up in the quotas.

Then you probably are using a fairly old version of Limesurvey.

What is the version you are using?

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.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 6 months ago - 3 years 6 months ago #207128 by tpartner
Replied by tpartner on topic Select answer in Q2 based on answer in Q1
You have some JS errors.

Code:
if('{Question07_SQ002}' == 'Y') {
    $('#question{QID} input:radio:eq(0)').trigger('click');
}
else {
    $('#question{QID} input:radio:eq(1)').trigger('click');
}

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 3 years 6 months ago by tpartner.
The following user(s) said Thank You: JasonZA
The topic has been locked.
  • JasonZA
  • JasonZA's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 6 months ago #207130 by JasonZA
Replied by JasonZA on topic Select answer in Q2 based on answer in Q1
Thanks to everyone for their assistance. @tpartner I will definitely give your js code a test in the morning. I'm a total novice with js.
The topic has been locked.
  • JasonZA
  • JasonZA's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 5 months ago #207359 by JasonZA
Replied by JasonZA on topic Select answer in Q2 based on answer in Q1
Thanks a lot, tpartner - the javascript works perfectly. I noticed that it doesn't work in 'all in one' view but works in 'question by question' view.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 5 months ago #207366 by tpartner
Replied by tpartner on topic Select answer in Q2 based on answer in Q1

I noticed that it doesn't work in 'all in one' view

You would need to add a listener on the checkboxes, something like this post - forums.limesurvey.org/forum/can-i-do-thi...der-of-a-list#203704

Cheers,
Tony Partner

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

Lime-years ahead

Online-surveys for every purse and purpose