Array question with answers in dropdown list

More
1 year 2 weeks ago #169270 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.

Please Log in or Create an account to join the conversation.

LimeSurvey Partners
More
1 year 2 weeks ago #169278 by tpartner
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.
Official LimeSurvey Partner - partnersurveys.com

Please Log in or Create an account to join the conversation.

More
1 year 2 weeks ago #169294 by Someone10
Attachments:

Please Log in or Create an account to join the conversation.

More
1 year 2 weeks ago #169319 by tpartner
Try this:

<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:

File Attachment:

File Name: limesurvey...9661.lss
File Size:18 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
Attachments:

Please Log in or Create an account to join the conversation.

More
1 year 2 weeks ago #169321 by Someone10
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

Please Log in or Create an account to join the conversation.

More
1 year 2 weeks ago #169325 by tpartner
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.
Official LimeSurvey Partner - partnersurveys.com

Please Log in or Create an account to join the conversation.

More
1 year 2 weeks ago #169330 by Someone10
I have imported the survey from that page with the code and I get the table without a column with text to add, what could have gone wrong?

Attachments:

Please Log in or Create an account to join the conversation.

More
1 year 2 weeks ago #169344 by tpartner
Yes, that's why I said you would have to extend the workaround for different columns.

<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:

File Attachment:

File Name: limesurvey...1969.lss
File Size:21 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
Attachments:

Please Log in or Create an account to join the conversation.

More
1 year 2 weeks ago - 1 year 2 weeks ago #169365 by Someone10
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: 1 year 2 weeks ago by Someone10.

Please Log in or Create an account to join the conversation.

More
1 year 2 weeks ago #169371 by Joffm
Hi,
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>');
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:
$('.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:

Please Log in or Create an account to join the conversation.

More
1 year 2 weeks ago #169377 by Someone10
I tried with this code but dont work
<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:

Please Log in or Create an account to join the conversation.

More
1 year 2 weeks ago #169382 by tpartner
That is because you have introduced some white-spaces after the back-slashes - these are not allowed.

<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:

File Attachment:

File Name: limesurvey...1925.lss
File Size:23 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
Attachments:

Please Log in or Create an account to join the conversation.

More
1 year 2 weeks ago #169389 by Someone10
Thank you very much for all, it works

Please Log in or Create an account to join the conversation.

More
9 months 1 week ago - 9 months 1 week ago #173474 by anaidgh
Hello, I try to use this, but it doesnt works for me, i want to create an array in which each row has a different droplist, but they´re the same for columns. I create an array (Numbers) with 1 as minimum an 5 maximum, but it still doesnt work.
I had Version 3.13 in spanish

Hope you can help me
Thank you!
Regards
Last edit: 9 months 1 week ago by anaidgh.

Please Log in or Create an account to join the conversation.

More
9 months 1 week ago #173503 by tpartner
This workaround is for an array-text type, not array-numbers.

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.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!