Welcome to the LimeSurvey Community Forum

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

Answer based on previous question

  • pimp_m
  • pimp_m's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
9 years 6 months ago #119644 by pimp_m
Answer based on previous question was created by pimp_m
Hi Friends,

Can anyone advise on multiple choice question condition.

Example question;

Q1. Please choose two:

[] Apple
[] Banana
[] Mango
[] Orange
[] Coconut
[] Grape

Answer for this question will not appear on next question.

Let say participant choose Banana & Mango for Q1, the answer for Q2 as follow:

Q2. Please choose two:

[] Apple
[] Orange
[] Coconut
[] Grape

If participant tick Orange & Coconut for Q1, the answer for Q2 as follow:

Q2. Please choose two:

[] Apple
[] Banana
[] Mango
[] Grape

thanks
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 6 months ago #119655 by tpartner
Replied by tpartner on topic Answer based on previous question
Please refer to the manual - Array Filter - www.limesurvey.org/manual/Question_type_...r_.28array_filter.29

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • pimp_m
  • pimp_m's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
9 years 6 months ago #119664 by pimp_m
Replied by pimp_m on topic Answer based on previous question
tq :)
The topic has been locked.
More
9 years 6 months ago #119671 by Ben_V
Replied by Ben_V on topic Answer based on previous question
Hi Tony,

I'm always quiet lost when I want to exclude (disable or hide) more than 1 answer option in the 2nd multiple-choice question:

Q1: Fruit or vegetable
[fruit] fruit
[veget] vegetable

Q2: Detailed list
[frui1] apple
[frui2] orange
[vege1] celery
[vege2] spinach

May you help me to write the correct jQuery syntax on a stone...

File Attachment:

File Name: limesurvey...5914.lss
File Size:16 KB

Benoît

EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 6 months ago - 9 years 6 months ago #119674 by tpartner
Replied by tpartner on topic Answer based on previous question
Hi Ben.

I would be inclined to insert a hidden copy of Q2 (call it qHidden) after Q1 and then use JavaScript to toggle the check-boxes in the hidden question. Corresponding food "group" sub-questions can be identified by the first 4 characters of sub-question codes.

Then you could filter Q2 by qHidden, allowing you to place it anywhere in the survey and make it mandatory (if necessary).

After adding that copy, place the following script placed in the source of Q1. I think the comments explain it but please ask if you are confused about any of it.

Code:
<script type="text/javascript" charset="utf-8">  
  $(document).ready(function() {
 
    // Identify the questions and IDs
    var q1ID = {QID};
    var q1 = $('#question'+q1ID);
    var qHidden = q1.nextAll('.multiple-opt:eq(0)');
    var qHiddenID = qHidden.attr('id').replace(/question/, '');  
 
    // Hide qHidden
    qHidden.hide();  
 
    // Listeners on the Q1 checkboxes
    $('input.checkbox', q1).change(function(e) {
 
      var q1Checkbox = $(this);
 
      // Define the food "group"
      var foodGroup = $(this).attr('id').split('X'+q1ID)[1].substr(0, 4);
 
      // Loop through subquestions within the food "group" in qHidden
      $('input.checkbox[id*="X'+qHiddenID+foodGroup+'"]', qHidden).each(function(i) {
        // Toggle the checkbox(es) in qHidden
        $(this).prop('checked', $(q1Checkbox).prop('checked'));
        $(this).nextAll('input[type="hidden"]:eq(0)').attr('value', $(q1Checkbox).nextAll('input[type="hidden"]:eq(0)').attr('value'));
        // Fire the Expression Manager checkconditions() function
        checkconditions(this.value, this.name, this.type);
      });
    });
  });
</script>

File Attachment:

File Name: limesurvey...14TP.lss
File Size:20 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 9 years 6 months ago by tpartner.
The following user(s) said Thank You: Ben_V
The topic has been locked.
More
9 years 6 months ago - 9 years 6 months ago #119696 by Ben_V
Replied by Ben_V on topic Answer based on previous question
Thank you Tony...It's really a great help !

This code is working fine and I'm sure it will help other users too :)

The other good news is that it's very easy to disable (not hide) the Q2 answers options, just setting properly Q2 array filter exclusion and setting the question relevance to 1.
Thanks again :)

Benoît

EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
Last edit: 9 years 6 months ago by Ben_V.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 6 months ago #119697 by tpartner
Replied by tpartner on topic Answer based on previous question
Ah, I didn't realize you wanted to exclude those answers, I thought you simply wanted to filter them. Another good reason to use the hidden question - it will work for both filter and exclusion-filter. ;)

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
9 years 6 months ago #119699 by Ben_V
Replied by Ben_V on topic Answer based on previous question

it will work for both filter and exclusion-filter


...the ultimate swiss army knife for multiple-choice questions !

Benoît

EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
9 years 6 months ago - 9 years 6 months ago #119707 by DenisChenu
Replied by DenisChenu on topic Answer based on previous question

tpartner wrote: I would be inclined to insert a hidden copy of Q2 (call it qHidden) after Q1 and then use JavaScript to toggle the check-boxes in the hidden question. Corresponding food "group" sub-questions can be identified by the first 4 characters of sub-question codes.

Hi,

I use same system for "filter by array" system.

And if question are not in same group : it's more easy.

See : demonstration.sondages.pro/676785 .

Tony and me have some different method (example : to find the baseSGQ : Tony use javascript, i use EM)

But in 2.06 : we don't need any javascript \o/ : each subquestion have own relevance equation.

Denis
PS: survey in freanch, but i know Ben read french ;)

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: 9 years 6 months ago by DenisChenu.
The following user(s) said Thank You: Ben_V
The topic has been locked.
More
9 years 6 months ago - 9 years 6 months ago #119716 by Ben_V
Replied by Ben_V on topic Answer based on previous question
Hi Denis, thank you for your tips & sample ;)

But in 2.06 : we don't need any javascript \o/ : each subquestion have own relevance equation.

Aspirin retail sales will probably plunge...

Benoît

EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
Last edit: 9 years 6 months ago by Ben_V.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
9 years 6 months ago #119718 by DenisChenu
Replied by DenisChenu on topic Answer based on previous question

Ben_V wrote:

But in 2.06 : we don't need any javascript \o/ : each subquestion have own relevance equation.

Aspirin retail sales will probably plunge...



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
9 years 6 months ago #119723 by Ben_V
Replied by Ben_V on topic Answer based on previous question
"pour le plaisir des yeux..."

Benoît

EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose