- Posts: 10
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Array with drop down box and numercial/text value
- rasputin
- Topic Author
- Offline
- New Member
Less
More
7 years 6 months ago #143419
by rasputin
Array with drop down box and numercial/text value was created by rasputin
Hello,
I have been looking around on the forum to find some answer but I did not get very far, sorry...
I am trying to add a new question type (an array probably) where the user has to select a value from a drop down box (e.g. country code) and to enter a text or numerical value that goes with it. Typical business question....
Ideally the user should be able to see a kind of grid in which he may select several codes from the drop down box and enter values for each of the drop down for it but initially a maximum number of answers that are split off into a separate questions would be cool ; so any kind of advice would be appreciated.
Thanks in advance.
I have been looking around on the forum to find some answer but I did not get very far, sorry...
I am trying to add a new question type (an array probably) where the user has to select a value from a drop down box (e.g. country code) and to enter a text or numerical value that goes with it. Typical business question....
Ideally the user should be able to see a kind of grid in which he may select several codes from the drop down box and enter values for each of the drop down for it but initially a maximum number of answers that are split off into a separate questions would be cool ; so any kind of advice would be appreciated.
Thanks in advance.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10104
- Thank you received: 3593
7 years 6 months ago #143425
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Array with drop down box and numercial/text value
Have a look at Denis' arrayTextAdapt plugin -
www.limesurvey.org/forum/plugins/104019-...ith-dropdwon-or-mask
. It allows arrays with different question types in each column.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- krosser
- Offline
- Elite Member
Less
More
- Posts: 222
- Thank you received: 10
5 years 11 months ago - 5 years 11 months ago #168813
by krosser
Is there any solution for this in the LS 3.6+?
I'm using the latest LS 3.22 hosted on LS servers, not installed locally.
Replied by krosser on topic Array with drop down box and numercial/text value
tpartner wrote: Have a look at Denis' arrayTextAdapt plugin - www.limesurvey.org/forum/plugins/104019-...ith-dropdwon-or-mask . It allows arrays with different question types in each column.
Is there any solution for this in the LS 3.6+?
I'm using the latest LS 3.22 hosted on LS servers, not installed locally.
Attachments:
Last edit: 5 years 11 months ago by krosser.
The topic has been locked.
- holch
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 11645
- Thank you received: 2739
5 years 11 months ago #168830
by holch
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Replied by holch on topic Array with drop down box and numercial/text value
Nope, not yet. I don't think Denis has adapted all of his great plugins to 3.x yet. You probably have to do it like in the old times with a workaround.
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10104
- Thank you received: 3593
5 years 11 months ago #168832
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Array with drop down box and numercial/text value
Are the drop-downs to be the same for all columns?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- krosser
- Offline
- Elite Member
Less
More
- Posts: 222
- Thank you received: 10
5 years 11 months ago #168837
by krosser
Yes.
It's just I'm trying to include a "Don't know" answer option into a multiple-choice question type, in which case, a simple "Don't know" as the last column isn't ideal. And a "No" answer would be also informative to have. Basically, this is in hope to aid the subsequent data analysis...
I'm using the latest LS 3.22 hosted on LS servers, not installed locally.
Replied by krosser on topic Array with drop down box and numercial/text value
tpartner wrote: Are the drop-downs to be the same for all columns?
Yes.
It's just I'm trying to include a "Don't know" answer option into a multiple-choice question type, in which case, a simple "Don't know" as the last column isn't ideal. And a "No" answer would be also informative to have. Basically, this is in hope to aid the subsequent data analysis...
I'm using the latest LS 3.22 hosted on LS servers, not installed locally.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10104
- Thank you received: 3593
5 years 11 months ago #168857
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Array with drop down box and numercial/text value
Place something like this in the question source:
Sample survey attached:
Code:
<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">Yes</option>\ <option value="2">No</option>\ <option value="3">Do not know</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>
Sample survey attached:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The following user(s) said Thank You: krosser
The topic has been locked.
- krosser
- Offline
- Elite Member
Less
More
- Posts: 222
- Thank you received: 10
5 years 11 months ago #168891
by krosser
I'm using the latest LS 3.22 hosted on LS servers, not installed locally.
Replied by krosser on topic Array with drop down box and numercial/text value
Great! It works, Tony! Much appreciated. :woohoo:
I am going to test-run it to see how it would show the responses in LS Stats and exported Excel files, since it isn't something like a hidden subquestion on top of it.
I am going to test-run it to see how it would show the responses in LS Stats and exported Excel files, since it isn't something like a hidden subquestion on top of it.
I'm using the latest LS 3.22 hosted on LS servers, not installed locally.
The topic has been locked.
- krosser
- Offline
- Elite Member
Less
More
- Posts: 222
- Thank you received: 10
5 years 11 months ago #168902
by krosser
I'm using the latest LS 3.22 hosted on LS servers, not installed locally.
Replied by krosser on topic Array with drop down box and numercial/text value
Okay, so I've tested on a survey and just as a note here can confirm that LS Statistics doesn't create graphs for the workaround. My guess is that LS doesn't recognise the question after it's modified. But fortunately the answers are still recorded and can be exported in Excel, which is great.
I'm using the latest LS 3.22 hosted on LS servers, not installed locally.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10104
- Thank you received: 3593
5 years 11 months ago - 5 years 11 months ago #168919
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Array with drop down box and numercial/text value
Yes, that is expected. The underlying question is an array-texts. No stats are ever given for text type questions.
If it would be easier to analyse with the codes instead of text-strings, you can try this (untested) script which will load the hidden input with numeric codes instead of text:
If it would be easier to analyse with the codes instead of text-strings, you can try this (untested) script which will load the hidden input with numeric codes instead of text:
Code:
<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">Yes</option>\ <option value="2">No</option>\ <option value="3">Do not know</option>\ </select>'); // Listeners $('.inserted-select', thisQuestion).on('change', function(i) { if($(this).val() != '') { $(this).closest('.answer-item').find('input:text').val($.trim($(this).val())).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 inputVal = $.trim($(this).val()); $('select.inserted-select', thisCell).val(inputVal); }); // Clean-up styles $('select.inserted-select', thisQuestion).css({ 'max-width': '100%' }); $('input:text', thisQuestion).css({ 'position': 'absolute', 'left': '-9999em' }); }); </script>
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 5 years 11 months ago by tpartner.
The following user(s) said Thank You: krosser
The topic has been locked.
- krosser
- Offline
- Elite Member
Less
More
- Posts: 222
- Thank you received: 10
5 years 11 months ago #168942
by krosser
Thanks. I didn't know that.
The 2nd version of the code works too.
I'm using the latest LS 3.22 hosted on LS servers, not installed locally.
Replied by krosser on topic Array with drop down box and numercial/text value
The underlying question is an array-texts. No stats are never given for text type questions.
Thanks. I didn't know that.
The 2nd version of the code works too.
I'm using the latest LS 3.22 hosted on LS servers, not installed locally.
Attachments:
The topic has been locked.
- lemmon
- Offline
- New Member
Less
More
- Posts: 16
- Thank you received: 0
5 years 3 months ago #179437
by lemmon
Replied by lemmon on topic Array with drop down box and numercial/text value
Thanks for this contribution. I have 2 questions:
1. How would I have to change the code to apply drop-down to only first column?
2. Would it be possible to have the second column only accept a numeric (decimal) input?
1. How would I have to change the code to apply drop-down to only first column?
2. Would it be possible to have the second column only accept a numeric (decimal) input?
The topic has been locked.