- Posts: 7
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Array question with answers in dropdown list
- Someone10
- Topic Author
- Offline
- New Member
Less
More
5 years 9 months ago #169270
by Someone10
Array question with answers in dropdown list was created by Someone10
Hi, I used this code for a survey
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
$('#question9769 .answer_cell_00SQ001 option[value=1]').text('No recurro');
$('#question9769 .answer_cell_00SQ001 option[value=2]').text('Arocena Gustavo');
$('#question9769 .answer_cell_00SQ001 option[value=3]').text('Aspra Manuel');
$('#question9769 .answer_cell_00SQ001 option[value=4]').text('Bravo Ricardo');
$('#question9769 .answer_cell_00SQ001 option[value=5]').text('Zalazar Martin');
$('#question9769 .answer_cell_00SQ002 option[value=1]').text('No recurro');
$('#question9769 .answer_cell_00SQ002 option[value=2]').text('Bravo Ricardo');
$('#question9769 .answer_cell_00SQ002 option[value=3]').text('Fernandez Flavio');
$('#question9769 .answer_cell_00SQ002 option[value=4]').text('Zalazar Martin');
$('#question9769 .answer_cell_00SQ002 option[value=5]').text('').hide();
});
</script>
But dont work, i used the Versión 3.8.0+180522.
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
$('#question9769 .answer_cell_00SQ001 option[value=1]').text('No recurro');
$('#question9769 .answer_cell_00SQ001 option[value=2]').text('Arocena Gustavo');
$('#question9769 .answer_cell_00SQ001 option[value=3]').text('Aspra Manuel');
$('#question9769 .answer_cell_00SQ001 option[value=4]').text('Bravo Ricardo');
$('#question9769 .answer_cell_00SQ001 option[value=5]').text('Zalazar Martin');
$('#question9769 .answer_cell_00SQ002 option[value=1]').text('No recurro');
$('#question9769 .answer_cell_00SQ002 option[value=2]').text('Bravo Ricardo');
$('#question9769 .answer_cell_00SQ002 option[value=3]').text('Fernandez Flavio');
$('#question9769 .answer_cell_00SQ002 option[value=4]').text('Zalazar Martin');
$('#question9769 .answer_cell_00SQ002 option[value=5]').text('').hide();
});
</script>
But dont work, i used the Versión 3.8.0+180522.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10630
- Thank you received: 3696
5 years 9 months ago #169278
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 question with answers in dropdown list
Can you provide an export of a small sample survey?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- Someone10
- Topic Author
- Offline
- New Member
Less
More
- Posts: 7
- Thank you received: 0
5 years 9 months ago #169294
by Someone10
Replied by Someone10 on topic Array question with answers in dropdown list
Ok
Attachments:
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10630
- Thank you received: 3696
5 years 9 months ago #169319
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 question with answers in dropdown list
Try this:
Here is your sample survey with that change:
Code:
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ $('#question{QID} .answer_cell_SQ001 option[value=1]').text('No recurro'); $('#question{QID} .answer_cell_SQ001 option[value=2]').text('Arocena Gustavo'); $('#question{QID} .answer_cell_SQ001 option[value=3]').text('Aspra Manuel'); $('#question{QID} .answer_cell_SQ001 option[value=4]').text('Bravo Ricardo'); $('#question{QID} .answer_cell_SQ001 option[value=5]').text('Zalazar Martin'); $('#question{QID} .answer_cell_SQ002 option[value=1]').text('No recurro'); $('#question{QID} .answer_cell_SQ002 option[value=2]').text('Bravo Ricardo'); $('#question{QID} .answer_cell_SQ002 option[value=3]').text('Fernandez Flavio'); $('#question{QID} .answer_cell_SQ002 option[value=4]').text('Zalazar Martin'); $('#question{QID} .answer_cell_SQ002 option[value=5]').text('').hide(); }); </script>
Here is your sample survey with that change:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The topic has been locked.
- Someone10
- Topic Author
- Offline
- New Member
Less
More
- Posts: 7
- Thank you received: 0
5 years 9 months ago #169321
by Someone10
Replied by Someone10 on topic Array question with answers in dropdown list
Thank you very much tony, it works. But another question arises. Is there any way to put in the middle of those columns a column in which you can enter text?
If there was some kind of code that would allow me in one of those columns to add text, I would fix many problems
If there was some kind of code that would allow me in one of those columns to add text, I would fix many problems
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10630
- Thank you received: 3696
5 years 9 months ago #169325
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 question with answers in dropdown list
For that, you could extend this workaround for separate columns -
www.limesurvey.org/forum/can-i-do-this-w...al-text-value#168857
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- Someone10
- Topic Author
- Offline
- New Member
Less
More
- Posts: 7
- Thank you received: 0
5 years 9 months ago #169330
by Someone10
Replied by Someone10 on topic Array question with answers in dropdown list
Attachments:
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10630
- Thank you received: 3696
5 years 9 months ago #169344
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 question with answers in dropdown list
Yes, that's why I said you would have to extend the workaround for different columns.
Survey attached:
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">Yes</option>\ <option value="2">No</option>\ <option value="3">Do not know</option>\ </select>'); $('.answer-item.answer_cell_X002', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\ <option value="">Please choose...</option>\ <option value="1">Red</option>\ <option value="2">Blue</option>\ <option value="3">Pink</option>\ <option value="3">Purple</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>
Survey attached:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The topic has been locked.
- Someone10
- Topic Author
- Offline
- New Member
Less
More
- Posts: 7
- Thank you received: 0
5 years 9 months ago - 5 years 9 months ago #169365
by Someone10
Replied by Someone10 on topic Array question with answers in dropdown list
thank you very much, one last question, if I want to add more select, how could I do? I want to do as in the image that I attached, that X004, X005 and X007 are dropdown
Attachments:
Last edit: 5 years 9 months ago by Someone10.
The topic has been locked.
- Joffm
- Away
- LimeSurvey Community Team
Less
More
- Posts: 12779
- Thank you received: 3940
5 years 9 months ago #169371
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Array question with answers in dropdown list
Hi,
I am sure you can find out by yourself.
In the javascript code you see
You see the X001 refers to the column code.
So just define your rows and columns and add the appropriate lines in the script as I did here:
Regards
Joffm
I am sure you can find out by yourself.
In the javascript code you see
Code:
// 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">Yes</option>\ <option value="2">No</option>\ <option value="3">Do not know</option>\ </select>');
So just define your rows and columns and add the appropriate lines in the script as I did here:
Code:
$('.answer-item.answer_cell_X005', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\ <option value="">Please choose...</option>\ <option value="1">AAA</option>\ <option value="2">BBB</option>\ <option value="3">Do not know</option>\ </select>'); $('.answer-item.answer_cell_X006', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\ <option value="">Please choose...</option>\ <option value="1">AAA</option>\ <option value="2">BBB</option>\ <option value="3">Do not know</option>\ </select>');
Regards
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:
The topic has been locked.
- Someone10
- Topic Author
- Offline
- New Member
Less
More
- Posts: 7
- Thank you received: 0
5 years 9 months ago #169377
by Someone10
Replied by Someone10 on topic Array question with answers in dropdown list
I tried with this code but dont work
with this survey
Code:
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ var thisQuestion = $('#question{QID}'); // Insert selects $('.answer-item.answer_cell_X004', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\ <option value="">Elige una opción...</option>\ <option value="1">a</option>\ <option value="2">b</option>\ </select>'); $('.answer-item.answer_cell_X005', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\ <option value="">Please choose...</option>\ <option value="1">a</option>\ <option value="2">b</option>\ <option value="3">c</option>\ </select>'); $('.answer-item.answer_cell_X007', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\ <option value="">Please choose...</option>\ <option value="1">a</option>\ <option value="2">b</option>\ <option value="3">c</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>
with this survey
Attachments:
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10630
- Thank you received: 3696
5 years 9 months ago #169382
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 question with answers in dropdown list
That is because you have introduced some white-spaces after the back-slashes - these are not allowed.
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.answer_cell_X004', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\ <option value="">Elige una opción...</option>\ <option value="1">Certificada</option>\ <option value="2">No Certificada</option>\ </select>'); $('.answer-item.answer_cell_X005', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\ <option value="">Please choose...</option>\ <option value="1">Suya</option>\ <option value="2">Cooperativa</option>\ <option value="3">Otro</option>\ <option value="3">Purple</option>\ </select>'); $('.answer-item.answer_cell_X007', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\ <option value="">Please choose...</option>\ <option value="1">No hace nada</option>\ <option value="2">Limpia Coop</option>\ <option value="3">Limpia+Trata</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>
Sample survey attached:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The topic has been locked.