- Posts: 7
- Thank you received: 0
- Forum
- English support forums
- Can I do this with LimeSurvey?
- Array question with answers in dropdown list
Array question with answers in dropdown list
<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.
Please Log in or Create an account to join the conversation.
- Posts: 8554
- Karma: 621
- Thank you received: 2624
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
- Posts: 8554
- Karma: 621
- Thank you received: 2624
<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.
Official LimeSurvey Partner - partnersurveys.com
Please Log in or Create an account to join the conversation.
If there was some kind of code that would allow me in one of those columns to add text, I would fix many problems
Please Log in or Create an account to join the conversation.
- Posts: 8554
- Karma: 621
- Thank you received: 2624
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
- Posts: 8554
- Karma: 621
- Thank you received: 2624
<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.
Official LimeSurvey Partner - partnersurveys.com
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
I am sure you can find out by yourself.
In the javascript code you see
// 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:
$('.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
Please Log in or Create an account to join the conversation.
<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
Please Log in or Create an account to join the conversation.
- Posts: 8554
- Karma: 621
- Thank you received: 2624
<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.
Official LimeSurvey Partner - partnersurveys.com
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
I had Version 3.13 in spanish
Hope you can help me
Thank you!
Regards
Please Log in or Create an account to join the conversation.
- Posts: 8554
- Karma: 621
- Thank you received: 2624
Can you provide a mockup of what you want?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
Please Log in or Create an account to join the conversation.