Welcome to the LimeSurvey Community Forum

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

Integrating checkbox and multiple choice dropdown menu in Array

  • jyu183
  • jyu183's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 9 months ago #226607 by jyu183
Please help us help you and fill where relevant:
Your LimeSurvey version: 3.27.26
Own server or LimeSurvey hosting:
Survey theme/template:
==================
Hi everyone, I have a question about making an Array question with differently optioned columns. 

Please see attached the file. What I want is the first column ("Check all that apply") to be a simple "checkbox" (you tick or untick); and the second column ("Level of education") to be a multiple choice dropdown menu where you can check multiple options rather than just one (eg you can choose both primary and secondary if you want); and the third column ("How is this incorporated into...") also to be a multiple choice dropdown menu, but with different answers from the second column. 

At the moment, I am using Array (text) format with the following script for dropdown: 

<script type="text/javascript" charset="utf-8">
    $(document).on('ready pjax:scriptcomplete',function(){
        var thisQuestion = $('#question{QID}');
 
        // Insert selects
        $('.answer-item', thisQuestion).append('<select class="inserted-select form-control list-question-select">\
                                                    <option value="">Please choose...</option>\
                                                    <option value="1">Early childhood & pre-primary</option>\
                                                    <option value="2">Primary</option>\
                                                    <option value="3">Secondary</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
        $('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%'
        });
        $('input:text', thisQuestion).css({
            'position': 'absolute',
            'left': '-9999em'
        });
    });
</script>

Please could you advice on whether this combination of checkbox + multiple option dropdown is possible? That would be really appreciated! Also it doesn't have to be Array (text); I just thought this would be the most apt format, but happy to change it to something else. 
Attachments:

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 9 months ago #226612 by Joffm
Hi,
1. where did you find this script?
There is nothing to select the column in it.

The usual script is this:
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="">...</option>\
  <option value="1">Mère</option>\
  <option value="2">Pére</option>\
  <option value="3">Soeur</option>\
  <option value="4">Frère</option>\
</select>');
    $('.answer-item.answer_cell_X002', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\
  <option value="">...</option>\
  <option value="1">masculin</option>\
  <option value="2">femelle</option>\
  <option value="3">autre chose </option>\
</select>');
 
    // Listeners
    $('.inserted-select', thisQuestion).on('change', function(i) {
      if($(this).val() != '') {
        $(this).closest('.answer-item').find('input:text').val($('option:selected', this).val()).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());
      $('select.inserted-select', thisCell).val(inputText);
    });
 
 
    // Clean-up styles
    $('select.inserted-select', thisQuestion).css({
      'max-width': '100%'
    });
    $('.with-select input:text', thisQuestion).css({
      'position': 'absolute',
      'left': '-9999em'
    });
  });
</script>

2. Is there any effect if somebody check your checkbox or not?

3. 

second column ("Level of education") to be a multiple choice dropdown menu

This will not work. Keep in mind the structure of the database.
But why? If you read your question it is single punch. If the child acqured a skill at a certain level (e.g. "Primary") the skills are present.
The third is multi punch, yes.

And therefore I recommend to split this question. 
You ask three different things.
It is overwhelming in this way.

Here something to read:
 

File Attachment:

File Name: surveyfriendly1.zip
File Size:977 KB


Of course you may use a question "array(numbers)" like this (depends on the amount of options in the third column)
 

Joffm




 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: jyu183

Please Log in to join the conversation.

  • jyu183
  • jyu183's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 9 months ago #226616 by jyu183
Hi Joffm,

Thanks for your response. So is it difficult to make a multiple choice dropdown menu in LimeSurvey?

There should be no effect following the respondent checking the checkbox. But I wanted to it to be multiple choice dropdown, because the purpose of this question is to find out at what levels those skills are taught. For instance, in some countries they might teach a skill both at primary AND secondary level, whereas in other countries they might teach a skill all three levels; while in other countries they might teach it at pre-primary AND secondary level (excluding primary level).

I will consider the checkbox as an alternative, but wanted to find out if making the answer as a multiple choice dropdown would have been possible.

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 9 months ago #226626 by tpartner
There is no direct support in LimeSurvey for multiple choice dropdowns (select elements). You would need to convert a normal multiple-choice question via JavaScript or create a custom question theme.

Additionally, I would hesitate to use them as they behave differently in different browsers so may confuse the respondent.

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: LISHANGQI, jyu183

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose