Welcome to the LimeSurvey Community Forum

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

Dynamic Dropdown-List (inside array question) based on multiple choice answers

  • yvp_test
  • yvp_test's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 2 months ago #245424 by yvp_test
Please help us help you and fill where relevant:
Your LimeSurvey version: LimeSurvey Cloud, Version 5.6.31
Own server or LimeSurvey hosting: LimeSurvey-Hosting
Survey theme/template: Bootswatch
==================
Hello everybody,
I have a seemingly simple problem regarding a conditional dropdown list inside an array question:

The relevant part consists (or should consist) of 2 question:

The first question is a multiple choice question, where the user has to select all modes of transport (out of a list of 12) he used for a specific journey (for example bike and train).

In the second question he has to give a detailed breakdown of the segments in his journey, for each sement he has to choose the mode of transport and the traveled distance.This should be an array question where the first column is a dropdown menu with the modes of transport he selected in question 1 and the second column a text input for the distance.

We have absoultely no clue how to implement this type of conditional/dynamic dropdown menu inside the array. I've found somewhat similar problems with dynamic dropdown memenus based on other dropdown menus, but as our dropdown list is created INSIDE an array, it seems a bit more complicated.

Below is our current code for question 2, where we got rid of question 1 and made a dropdown list with ALL modes of transport. This is not our prefered way of doing this tho. 

Code:
<script type="text/javascript" charset="utf-8">
    $(document).on('ready pjax:scriptcomplete',function(){
        var thisQuestion = $('#question{QID}');
 
        // Insert selects
        $('.answer-item.answer_cell_X1', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\
                                                    <option value="">Bitte auswählen, falls zutreffend...</option>\
                                                    <option value="1">zu Fuß</option>\
                                                    <option value="2">Fahrrad</option>\
                                                    <option value="3">Pkw (Benzin/Diesel) als Fahrer*in</option>\
                                                    <option value="4">Pkw mit alternativem Antrieb als Fahrer*in (z. B. Elektro, Wasserstoff)</option>\
                                                    <option value="5">Pkw (Benzin/Diesel) als Mitfahrer*in</option>\
                                                    <option value="6">Pkw mit anderem alternativem Antrieb als Mitfahrer*in (z.B. Elektro, Wasserstoff)</option>\
                                                    <option value="7">Bus</option>\
                                                    <option value="8">Straßenbahn, U-Bahn</option>\
                                                    <option value="9">Bahn (inkl. Schnell-/ Lokalbahn)</option>\
                                                    <option value="10">Taxi</option>\
                                                    <option value="11">Sonstiges (z.B. E-Scooter, (E-)Motorrad)</option>\
                                                    <option value="12">Elektro-Fahrrad</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>
<p>Hier steht ein Erklärungstext</p>

Also the survey example:

File Attachment:

File Name: limesurvey...3979.lsq
File Size:22 KB


Thanks in advance!

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 2 months ago - 1 year 2 months ago #245425 by Joffm
Hi,.
please never provide neither lsg (group) nor lsq (question) exports.
Both are language sensitive.
 You can't import them into a survey with a different base language.
We don't want to guess the language you used.
Furthermore the surveywide settings are missing. They may be quite important.
Help us to help you.

A lss(survey) export can be easily imported and contains everything needed.

Joffm

P.S.
Did you have look at the several surveys about public transport of the students of TUE?
There were similar requirements - as far as I remember.

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 year 2 months ago by Joffm.

Please Log in to join the conversation.

  • yvp_test
  • yvp_test's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 2 months ago #245427 by yvp_test
Oh, sorry about the survey file, that was an accident.

Regarding the similar surveys you mentioned: could you give me a hint where to find them? My research wasn't successful.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 2 months ago #245431 by Joffm
Hi,
sorry but what for do you ask the first question?
There are only 10 items. So why filter them?
I do not see any necessity at all, because there is no difference if I select 4 or 5 modes before or I select them directly in the second question.
Here some ideas from former threads about trips and stages




Joffm

 

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose