- Posts: 2
- Thank you received: 0
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
- Topic Author
- Offline
- New Member
Less
More
3 years 3 months ago #210080
by Jenna81
Creating an array with variable question types was created 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.
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
- Away
- LimeSurvey Community Team
Less
More
- Posts: 12922
- Thank you received: 3977
3 years 3 months ago #210087
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Creating an array with variable question types
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", ...
Joffm
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
- Topic Author
- Offline
- New Member
Less
More
- Posts: 2
- Thank you received: 0
3 years 3 months ago #210116
by Jenna81
Replied by Jenna81 on topic Creating an array with variable question types
Thank you so much, Joffm! That is supremely helpful!
The topic has been locked.