Welcome to the LimeSurvey Community Forum

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

2 Array Type in a single question

  • jackuars
  • jackuars's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
6 years 8 months ago - 6 years 8 months ago #156098 by jackuars
2 Array Type in a single question was created by jackuars
From a previous question that says "How many children do you have?", I want to create a question that asks the age and gender of the child like this, instead of having to ask 6 different questions for each child if they have 3 children.

But this means that a single question would have two question types.
Last edit: 6 years 8 months ago by jackuars.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 8 months ago #156103 by tpartner
Replied by tpartner on topic 2 Array Type in a single question
Have a look at Denis' arrayTextAdapt plugin - www.limesurvey.org/index.php?option=com_...textadapt&Itemid=729

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • jackuars
  • jackuars's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
6 years 8 months ago #156104 by jackuars
Replied by jackuars on topic 2 Array Type in a single question
It seems that only from v2.05 Limesurvey supports extensions. How can I know what version of Limesurvey am running?

And also how can I update Limesurvey?
The topic has been locked.
  • jackuars
  • jackuars's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
6 years 8 months ago #156106 by jackuars
Replied by jackuars on topic 2 Array Type in a single question
Also we dont have the permission to add extensions because it's linked to the app.

Is it possible to perform this question using Javascript? Also how?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 8 months ago #156111 by tpartner
Replied by tpartner on topic 2 Array Type in a single question
Yes, it could be done with JavaScript but the required code would depend on the version. You should see that at the bottom of any admin screen.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • jackuars
  • jackuars's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
6 years 8 months ago #156112 by jackuars
Replied by jackuars on topic 2 Array Type in a single question
Thanks. It's version 2.51.

How can i do it using JS?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 8 months ago #156117 by tpartner
Replied by tpartner on topic 2 Array Type in a single question
Create an Array (Texts) type question and set "Numbers only" to "On".

Insert the following script into the question source. Note that since the question is numbers-only, the data recorded in column-2 will be 1 or 2, not M or F.

Code:
<script type="text/javascript" charset="utf-8">
  $(document).ready(function(){  
 
    // Identify this question
    var qID = {QID};
    var thisQuestion = $('#question'+qID);
 
    // Assign column-specific classes
    $('table.subquestion-list tr', thisQuestion).each(function(i) {
 
      $('> *:gt(0)', this).each(function(i){
        $(this).addClass('column-'+(i+1));
        $(this).attr('data-column', i+1);
      });
    });
 
    // Hide the text inputs in columns 2
    $('.column-2 input[type="text"]', thisQuestion).hide();
 
 
    // Loop through all column-2 inputs
    $('.answer-item.column-2 input[type="text"]', thisQuestion).each(function(i) {
      var thisID = $(this).attr('id');
      var thisValue = $(this).val();
 
      // Insert the radios
      $(this).parent().addClass('radio').append('<span class="inserted-radio-wrapper">\
                    <input id="'+thisID+'-M" class="radio" value="1" name="'+thisID.replace(/answer/, '')+'_radio" type="radio">\
                    <label class="control-label radio-label" for="'+thisID+'-M">Male</label>\
                  </span>\
                  <span class="inserted-radio-wrapper">\
                    <input id="'+thisID+'-F" class="radio" value="2" name="'+thisID.replace(/answer/, '')+'_radio" type="radio">\
                    <label class="control-label radio-label" for="'+thisID+'-F">Female</label>\
                  </span>');
 
      // Initial radio states
      $(this).closest('td').find('input[type="radio"][value="'+thisValue+'"]').prop('checked', true);
    });
 
    // Listener on the radios
    $('.answer-item.column-2 input[type="radio"]', thisQuestion).on('click', function() {
      var thisInput = $(this).closest('td').find('input[type="text"]');
      $(this).closest('td').find('input[type="text"]').val($(this).val());
      checkconditions($(thisInput).val(), $(thisInput).attr('name'), 'text');
    });
 
    // Insert some clean-up styles (could be placed in template.css)
    $('<style type="text/css">\
      #question'+qID+' thead th, #question'+qID+' .answer-item.column-2 {\
        text-align:center \
      }\
      #question'+qID+' .answer-item.column-2 .inserted-radio-wrapper {\
        display: inline-block;\
        margin: 10px 10px 0 20px;\
      }\
      #question'+qID+' .answer-item.column-2 label {\
        padding: 0;\
      }\
      #question'+qID+' .answer-item.column-2 .radio-label {\
        padding-left: 3px;\
        margin-right: 3px;\
      }\
      @media only screen and (max-width: 801px) {\
        label.visible-xs-block {\
          text-align: center;\
        }\
        label.visible-xs-block::before, label.visible-xs-block::after {\
          display: none;\
        }\
      }\
    </style>').appendTo( "head" )    
  });
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...6-20.lss
File Size:21 KB

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