Welcome to the LimeSurvey Community Forum

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

Answer options based on previous question

More
6 years 4 months ago #160372 by AdinaNica1
Replied by AdinaNica1 on topic Answer options based on previous question
Super! The demo is working (and this didn't happen to the previous demos)!
Can I use this script if the second question is multiple (I need to include a list of brands here)?
Adina
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 4 months ago #160375 by Joffm
Replied by Joffm on topic Answer options based on previous question
Adina,

did you try?
Of course. The "trick" is the array filter. Everywhere you can use an array filter it will work.



Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 4 months ago #160381 by Joffm
Replied by Joffm on topic Answer options based on previous question
Well, not to be confused.

I only said "you can do that". But of course you do not

In reality you use just subquestion relevance if the second question is multiple.

The whole workaround is only necessary, because there is no subquestion relevance in single punch questions (there are no subquestions)

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
More
6 years 4 months ago #160383 by AdinaNica1
Replied by AdinaNica1 on topic Answer options based on previous question
Excellent! I will try now!! Many many thanks!!!
The topic has been locked.
More
6 years 4 months ago #160386 by AdinaNica1
Replied by AdinaNica1 on topic Answer options based on previous question
Hi, Joff!
What I have to do:

Q1 (single) City

Q2 (multiple) Brands ever used, each city has a list of brands that are present
BUC : 'CL1,CL3,CL5',
BV : 'CL1,CL2,CL3,CL4',
IS : 'CL2,CL3,CL4,CL5',
TM : 'CL1,CL4,CL6'

Q3 (single) Brand used most often - show only the brands that are ticked in Q2



I tried to implement the scripts in my survey and the version that finally worked for me was:

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

// The Q2 options corresponding to the Q1 options
ListaClinici = {
BUC : 'CL1,CL3,CL5',
BV : 'CL1,CL2,CL3,CL4',
IS : 'CL2,CL3,CL4,CL5',
TM : 'CL1,CL4,CL6'
};

// Identify this question
var thisQuestion = $('#question{QID}')

// The checked option in Q1
var q1Ans = '{Q1}';

// Hide all of the clinics
$('.answer-item', thisQuestion).hide();

// Now show the appropriate ones
$(ListaClinici[q1Ans].split(',')).each(function(i){
$('.answer-item[id$="'+{QID}+this+'"]').show();
});

// Uncheck all hidden radios (in case page has been seen before)
$('.answer-item:hidden input.radio', thisQuestion).prop('checked', false);
});
</script>

Now, I have the following situation:

In Q3, i need to show only the brands that are ticked in Q2 (multiple answer). I put the array filter and it doesn't work properly, it doesn't show the correct list of chosen answers in Q2. For some cities it works, for some other it doesn't.
I also attach the survey, I think it is something I miss here! Can you have a look on the syntax?
Many many thanks! [attachment=11079]Clinics test adina.lss
The topic has been locked.
More
6 years 4 months ago #160387 by AdinaNica1
Replied by AdinaNica1 on topic Answer options based on previous question
In the meantime I noticed that only if I tick CL3 in Q2 I get the error
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 4 months ago #160389 by Joffm
Replied by Joffm on topic Answer options based on previous question
Hello,

in this scenario you do not need any javascript. In this case it is nonsense.

Remember: This thread is about filtering single -> single. (single has no subquestion relevance)

Just use subquestion relevance in Q2 and array filter in Q3.
Q2:

Q3:



well, it's German, but you see.
And I changed these IMHO silly "lettercodes (A1, C3)" to numerical codes.

And remember: To use "array filter" the codes of Q2 and Q3 have to be exactly equal.

See example:

File Attachment:

File Name: limesurvey...3274.lss
File Size:21 KB


Best regards
Joffm

And, the best is to read the manual about question types and about "Adding answers and subquestions"

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: AdinaNica1
The topic has been locked.
More
6 years 4 months ago #160391 by AdinaNica1
Replied by AdinaNica1 on topic Answer options based on previous question
This is the initial option I used, I can't remember why it did't work!
I will try once again! Many many thanks!
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 4 months ago #160394 by Joffm
Replied by Joffm on topic Answer options based on previous question
Hi,
instead of saying "doesn't work" better you send a sample of your survey (*.lss)
so that we can see.

Best regards
Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
More
6 years 4 months ago #160412 by AdinaNica1
Replied by AdinaNica1 on topic Answer options based on previous question
Hey, it's working now :) :)
Wonderful! Thanks a lot!
Adina
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose