Welcome to the LimeSurvey Community Forum

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

Creating an array with variable question types

  • Jenna81
  • Jenna81's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 3 months ago #210080 by Jenna81
I am trying to create a question group (social network survey) such that a participant responds to a dropdown question (numbers 1-50), and then an array is generated with the amount of rows to match the number chosen.

Within the array that is generated, I would like to have seven column headings with all but one being dropdown menus. The menu would be different for each question.

Is this possible in LimeSurvey? I know that it is not part of the available roster of array options, but I imagine this could be accomplished through a workaround. My coding expertise is admittedly limited.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 3 months ago #210087 by Joffm
Hi,
the first you have to do with subquestion relevance.
When is the first line of the array is displayed? When the number is greater than 0. (Q1.NAOK>0)
When is the second line of the array is displayed? When the number is greater than 1. (Q1.NAOK>1)
When is the third line of the array is displayed? When the number is greater than 2. (Q1.NAOK>2)
And so on.

And to have drop-downs in your array, here ist a workaround.
Only for two columns, but you have to adapt anyway.
You see that the columns are coded as "X001", "X002", ...
Code:
<script type="text/javascript" charset="utf-8">
  $(document).on('ready pjax:scriptcomplete',function(){
    var thisQuestion = $('#question{QID}');
 
    // Insert selects
    $('.answer-item.answer_cell_X001', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\
      <option value="">Please choose...</option>\
      <option value="1">Not at all</option>\
      <option value="2">A little</option>\
      <option value="3">Quite a lot</option>\
      <option value="4">Very much</option>\
    </select>');
    $('.answer-item.answer_cell_X002', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\
      <option value="">Please rate...</option>\
      <option value="1">Certain I cant do it</option>\
      <option value="2">2</option>\
      <option value="3">3</option>\
      <option value="4">4</option>\
      <option value="5">5</option>\
      <option value="6">6</option>\
      <option value="7">7</option>\
      <option value="8">8</option>\
      <option value="9">9</option>\
      <option value="10">Certain I can do it</option>\
    </select>');
 
    // Listeners
    $('.inserted-select', thisQuestion).on('change', function(i) {
      if($(this).val() != '') {
        $(this).closest('.answer-item').find('input:text').val($.trim($('option:selected', this).text())).trigger('change');
      }
      else {
        $(this).closest('.answer-item').find('input:text').val('').trigger('change');
      }
    });
 
    // Returning to page
    $('.with-select input:text', thisQuestion).each(function(i) {
      var thisCell = $(this).closest('.answer-item');
      var inputText = $.trim($(this).val());
      var selectval = $('select.inserted-select option', thisCell).filter(function () { return $(this).html() == inputText; }).val();
      $('select.inserted-select', thisCell).val(selectval);
    });
 
    // Clean-up styles
    $('select.inserted-select', thisQuestion).css({
      'max-width': '100%'
    });
    $('.with-select input:text', thisQuestion).css({
      'position': 'absolute',
      'left': '-9999em'
    });
  });
</script>





Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • Jenna81
  • Jenna81's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 3 months ago #210116 by Jenna81
Thank you so much, Joffm! That is supremely helpful!
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose