Welcome to the LimeSurvey Community Forum

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

Additional conditional question in array question problem

More
6 years 9 months ago - 6 years 9 months ago #155231 by ziu
Hi everyone,
I was using LimeSurvey a couples of year ago and I am really shocked how it looks like now! It 's brilliant! :)
I 've got some question. I 'm not sure if it 's possible. Could anyone help me?
I 've got some array question in my survey, sth like that:

Do you use that stuff in your life?
AAlwaysSometimesNever
BAlwaysSometimesNever
CAlwaysSometimesNever


I 'd love to add some additional question. If someone would say: "Never". I would ask him or her: "Would you like to try to use it?" and give Yes/No variants.
How can I do this?

Is it possible to make it in one array question (for example some array question with dual scale?). Or should I use some relevance equation?
Please let me know if anyone have some idea. I would be grateful!

Thank you for your time and I wish you all the best :)
Peter

PS. I 'm using LimeSurvey in Version 2.64.7+170404
PS2. The problem is that I have not only three questions in array (A,B,C) but about 15.
Last edit: 6 years 9 months ago by ziu. Reason: I wanted to make title more accurate
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 9 months ago #155233 by tpartner
Replied by tpartner on topic Conditional question in array question problem
You could use JavaScript to insert the secondary questions into the array but I think it would behave poorly on mobile devices.

I would keep the secondary questions separate and hide/show them with relevance.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: ziu
The topic has been locked.
More
6 years 9 months ago #155234 by ziu
Yeah, that 's great idea with relevance. But I have got about 15 questions in array. It could be a little bit annoying to have 15 more questions if respondent answer "Never" in all questions in array.
For me using mobile devices are not so important.
The topic has been locked.
More
6 years 9 months ago #155236 by Deusdeorum
As tdpartner says you could use custom JS or create another array question and set conditions on the previous answer. Take a look at attached .lss file
The following user(s) said Thank You: ziu
The topic has been locked.
More
6 years 9 months ago #155237 by ziu
Thank you Deusdeorum! This is exactly what i was looking for :)
Now I can ask the question only when respondent answer "Never" in first question array.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 9 months ago - 6 years 9 months ago #155239 by tpartner
Replied by tpartner on topic Conditional question in array question problem

But I have got about 15 questions in array. It could be a little bit annoying to have 15 more questions if respondent answer "Never" in all questions in array.

In that case, I would do this with a combination of an array and a hidden multiple-choice question.
  1. Add a fourth answer to the array with text "I would like to try it".
  2. Insert a multiple-choice question directly after the array.
  3. Give the multiple-choice a question class "hidden" to hide it.
  4. Give the multiple-choice exactly the same sub-questions as the array.
  5. Place relevance on the multiple-choice sub-questions to display them if the corresponding "Never" is checked in the array.
  6. Place the following script in the source of the array. It will remove the radios from the last column of the array and move the multiple-choice sub-questions into those cells.
Code:
<script type="text/javascript" charset="utf-8">
  $(document).ready(function() {
 
    // Identify the questions
    var qID = {QID};
    var thisQuestion = $('#question'+qID);
    var nextID = $(thisQuestion).nextAll('.multiple-opt:eq(0)').attr('id').replace(/question/, '');
    var nextQuestion = $('#question'+nextID);
 
    // Assign column-specific classes
    $('table.subquestion-list tr', thisQuestion).each(function(i) { 
      $('> *:gt(0)', this).each(function(i){
        $(this).addClass('column-'+(i+1));
      });
    });
 
    // Loop through the array rows
    $('tr.answers-list', thisQuestion).each(function(i) {
      var thisCode = $(this).attr('id').split('X'+qID)[1];
 
      // Remove the radios from the last column
      $('.answer-item:last *', this).remove();
 
      // Insert the checkboxes
      $('.answer-item:last', this).removeClass('radio').append($('.answer-item[id$="X'+nextID+thisCode+'"]', nextQuestion)); 
    });
 
    // A function to handle the last-column label
    function handleLastlabel() {
      if($('.column-3 input.radio:checked', thisQuestion).length == 0) {
        $('thead .column-4', thisQuestion).css({
          'opacity': 0.35
        });
      }
      else {
        $('thead .column-4', thisQuestion).css({
          'opacity': 1
        });
      }
    }
    handleLastlabel();
    $('input.radio', thisQuestion).on('click', function(e) {
      handleLastlabel();
    });
 
    // Some clean-up stuff 
    if($(window).width() > 800) {
      $('.answer-item:last-child .label-text', thisQuestion).hide();
    }
    $(window).resize(function() { 
      if($(window).width() > 800) {
        $('.answer-item:last-child .label-text', thisQuestion).hide();
      }
      else {
        $('.answer-item:last-child .label-text', thisQuestion).show();
      }
    });
    $('.answer-item:last-child .checkbox-item', thisQuestion).css({
      'padding': 0,
      'margin': 0
    }); 
  });
</script>





Sample survey:

File Attachment:

File Name: limesurvey...5-26.lss
File Size:22 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 6 years 9 months ago by tpartner.
The topic has been locked.
More
6 years 9 months ago #155252 by ziu
Oh God, this Community is so helpful. I 'm really amazed that you answer mi so fast and give two great solutions!
tpartner, I 'm not sure if I make sth wrong or your uploaded lss file is correct, but I 've got quite different situation in survey I 've imported. Am I doing sth wrong?
Thank you for your code tpartner. I am really grateful.


I 'm not sure which solution I 'm going to use becouse both looks great :)
Attachments:
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 9 months ago #155253 by tpartner
Replied by tpartner on topic Conditional question in array question problem
The imported survey works for me in all browsers. Can you activate a test survey so I can see if there are any errors?

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
6 years 9 months ago - 6 years 9 months ago #155279 by Deusdeorum
Replied by Deusdeorum on topic Conditional question in array question problem
Nice solution tpartner! I can confirm that it works in all browsers here too version Version 2.59.1+170116.
Last edit: 6 years 9 months ago by Deusdeorum.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose