Check out the LimeSurvey source code on GitHub!
Welcome, Guest
Username: Password:

TOPIC: Array question with answers in dropdown boxes

Array question with answers in dropdown boxes 2 years 5 months ago #109868

  • tpartner
  • tpartner's Avatar
  • Online
  • LimeSurvey Team
  • Posts: 6571
  • Thank you received: 1477
  • Karma: 579
What has changed on your installation.

Do you get any JavaScript errors?


.
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The administrator has disabled public write access.

Array question with answers in dropdown boxes 2 years 5 months ago #109910

  • ricardo01
  • ricardo01's Avatar
  • Offline
  • Expert Lime
  • Posts: 117
  • Thank you received: 1
  • Karma: 0
the only thing that has changed is that I updated my installation...I'm now using 2.05+ (140520)
The administrator has disabled public write access.

Array question with answers in dropdown boxes 2 years 5 months ago #109911

  • tpartner
  • tpartner's Avatar
  • Online
  • LimeSurvey Team
  • Posts: 6571
  • Thank you received: 1477
  • Karma: 579
2.05 uses a different version of jQuery which may be causing some errors. Can you activate a test survey for us to see>
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The administrator has disabled public write access.

Array question with answers in dropdown boxes 2 years 1 month ago #113816

  • ricardo01
  • ricardo01's Avatar
  • Offline
  • Expert Lime
  • Posts: 117
  • Thank you received: 1
  • Karma: 0
Hi guys,

I'm coming back to this issiue. I want to create a with answers in dropdown boxes...I'm using the Tony's code. The problem is that the column doesn't show up...just an empty space. This is a link to an example...

ayura.udea.edu.co/limesurvey/index.php/561473/lang-es

this is the code I'm using

Disponibilidad y estado actual de la infraestructura del nivel preescolar
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {

var qID = {QID};

// Define the select element (dropdown)
var select1 = '<select class="insertedSelect"> \
<option value="">-- Please Choose --</option> \
<option value="Nuevo">Nuevo</option> \
<option value="Reparado">Reparado</option> \
<option value="Deteriorado">Deteriorado</option> \
<option value="Inservible">Inservible</option> \
</select>';

// Hide the text inputs
$('#question'+qID+' .answer_cell_004 input[type="text"]').hide().parent().hide();

// Insert the select elements
$('#question'+qID+' .answer_cell_004').append(select1);

// Initially select an option if the question has already been answered
$('#question'+qID+' .answer_cell_004 input[type="text"]').each(function(i){
if($(this).val()) {
$(this).closest('td').find('.insertedSelect').val($(this).val());
}
});

// Listener on the dropdowns - insert selected values into hidden text input
$('.insertedSelect').change(function() {
$(this).closest('td').find('input[type="text"]').val($(this).val());
});
});
</script>
The administrator has disabled public write access.

Array question with answers in dropdown boxes 2 years 1 month ago #113827

  • tpartner
  • tpartner's Avatar
  • Online
  • LimeSurvey Team
  • Posts: 6571
  • Thank you received: 1477
  • Karma: 579
Ah, in pre-2.05 versions the text inputs were placed inside the labels, which was poorly formed HTML. Now they are siblings of the labels.

Change this line:
$('#question'+qID+' .answer_cell_004 input[type="text"]').hide().parent().hide();

To this:
$('#question'+qID+' .answer_cell_004 input[type="text"]').hide();

So, the complete code:
<script type="text/javascript" charset="utf-8">
	$(document).ready(function() {
 
		var qID = {QID};
 
		// Define the select element (dropdown)
		var select1 = '<select class="insertedSelect">\
					<option value="">-- Please Choose --</option>\
					<option value="Nuevo">Nuevo</option>\
					<option value="Reparado">Reparado</option>\
					<option value="Deteriorado">Deteriorado</option>\
					<option value="Inservible">Inservible</option>\
				</select>';
 
		// Hide the text inputs
		$('#question'+qID+' .answer_cell_004 input[type="text"]').hide();
 
		// Insert the select elements
		$('#question'+qID+' .answer_cell_004').append(select1);
 
		// Initially select an option if the question has already been answered
		$('#question'+qID+' .answer_cell_004 input[type="text"]').each(function(i){
			if($(this).val()) {
				$(this).closest('td').find('.insertedSelect').val($(this).val());
			}
		});
 
		// Listener on the dropdowns - insert selected values into hidden text input
		$('.insertedSelect').change(function() {
			$(this).closest('td').find('input[type="text"]').val($(this).val());
		});
	});
</script>
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last Edit: 2 years 1 month ago by tpartner.
The administrator has disabled public write access.

Array question with answers in dropdown boxes 5 months 2 weeks ago #137890

  • Juanoche
  • Juanoche's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 8
  • Karma: 0
Hello,
I'm using versión Versión 2.50+ Build 160526 and this script don't work for me (spanish survey). Any help is apreciated..

<script type="text/javascript" charset="utf-8">

$(document).ready(function(){

$('#question298 .answer_cell_00SQ001 option[value=1]').text('No recurro');
$('#question298 .answer_cell_00SQ001 option[value=2]').text('Arocena Gustavo');
$('#question298 .answer_cell_00SQ001 option[value=3]').text('Aspra Manuel');
$('#question298 .answer_cell_00SQ001 option[value=4]').text('Bravo Ricardo');
$('#question298 .answer_cell_00SQ001 option[value=5]').text('Zalazar Martin');

$('#question298 .answer_cell_00SQ002 option[value=1]').text('No recurro');
$('#question298 .answer_cell_00SQ002 option[value=2]').text('Bravo Ricardo');
$('#question298 .answer_cell_00SQ002 option[value=3]').text('Fernandez Flavio');
$('#question298 .answer_cell_00SQ002 option[value=4]').text('Zalazar Martin');
$('#question298 .answer_cell_00SQ002 option[value=5]').text('').hide();

});

</script>
The administrator has disabled public write access.

Array question with answers in dropdown boxes 5 months 2 weeks ago #137914

  • tpartner
  • tpartner's Avatar
  • Online
  • LimeSurvey Team
  • Posts: 6571
  • Thank you received: 1477
  • Karma: 579
I'm not sure you have correct jQuery selectors. If, for example, you have x-scale subquestion codes X1 and X2, the code should look like this (no need to replace {QID}):

<script type="text/javascript" charset="utf-8">		
	$(document).ready(function(){
		$('#question{QID} .answer_cell_X1 option[value=1]').text('No recurro');
		$('#question{QID} .answer_cell_X1 option[value=2]').text('Arocena Gustavo');
		$('#question{QID} .answer_cell_X1 option[value=3]').text('Aspra Manuel');
		$('#question{QID} .answer_cell_X1 option[value=4]').text('Bravo Ricardo');
		$('#question{QID} .answer_cell_X1 option[value=5]').text('Zalazar Martin');
 
		$('#question{QID} .answer_cell_X2 option[value=1]').text('No recurro');
		$('#question{QID} .answer_cell_X2 option[value=2]').text('Bravo Ricardo');
		$('#question{QID} .answer_cell_X2 option[value=3]').text('Fernandez Flavio');
		$('#question{QID} .answer_cell_X2 option[value=4]').text('Zalazar Martin');
		$('#question{QID} .answer_cell_X2 option[value=5]').remove();
	});
</script>
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The administrator has disabled public write access.

Array question with answers in dropdown boxes 5 months 2 weeks ago #137923

  • DenisChenu
  • DenisChenu's Avatar
  • Online
  • Moderator Lime
  • Posts: 9580
  • Thank you received: 1374
  • Karma: 390
Hi,

Actually for such solution : you have a plugin : www.limesurvey.org/forum/plugins/104019-...ith-dropdwon-or-mask

It work on a 2.50 last time i tested.
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (use private message).
The administrator has disabled public write access.

Array question with answers in dropdown boxes 5 months 2 weeks ago #137950

  • Juanoche
  • Juanoche's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 8
  • Karma: 0
tpartner wrote:
I'm not sure you have correct jQuery selectors. If, for example, you have x-scale subquestion codes X1 and X2, the code should look like this (no need to replace {QID})
Tony thanks for showing me the light. I was writting y-scale subquestion codes...
The administrator has disabled public write access.

Array question with answers in dropdown boxes 5 months 2 weeks ago #137951

  • Juanoche
  • Juanoche's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 8
  • Karma: 0
DenisChenu wrote:
Hi,

Actually for such solution : you have a plugin : www.limesurvey.org/forum/plugins/104019-...ith-dropdwon-or-mask

It work on a 2.50 last time i tested.

DenisChenu I had already seen that plugin but unfortunately I get a 500 error on my server when I install it and try to acces survey settings / Plugins
The administrator has disabled public write access.

Array question with answers in dropdown boxes 5 months 2 weeks ago #137953

  • DenisChenu
  • DenisChenu's Avatar
  • Online
  • Moderator Lime
  • Posts: 9580
  • Thank you received: 1374
  • Karma: 390
Juanoche wrote:
DenisChenu wrote:
Hi,

Actually for such solution : you have a plugin : www.limesurvey.org/forum/plugins/104019-...ith-dropdwon-or-mask

It work on a 2.50 last time i tested.

DenisChenu I had already seen that plugin but unfortunately I get a 500 error on my server when I install it and try to acces survey settings / Plugins
See github.com/SondagesPro/LS-arrayTextAdapt...suecomment-223626556

I can not reproduce the issue : then need tester.
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (use private message).
The administrator has disabled public write access.

Array question with answers in dropdown boxes 1 month 2 weeks ago #143401

  • ramzus
  • ramzus's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 7
  • Karma: 0
Hi tpartner,

I used this solution and it was very helpful, but now i want to show the selected dropdown text in the next question but the Limesurvey replacement field properties shown only the code selected.

Thanks
The administrator has disabled public write access.

Array question with answers in dropdown boxes 1 month 2 weeks ago #143406

  • tpartner
  • tpartner's Avatar
  • Online
  • LimeSurvey Team
  • Posts: 6571
  • Thank you received: 1477
  • Karma: 579
Err...which solution. There are many in this thread, some of which are years old. It may be better to start a new thread describing exactly what you did and the details of your LimeSurvey environment.
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The administrator has disabled public write access.

Array question with answers in dropdown boxes 1 month 2 weeks ago #143413

  • ramzus
  • ramzus's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 7
  • Karma: 0
The solution for the array question with text answers in a dropdown box i want to show the selected dropdown text in the next question but the Limesurvey replacement field properties shown only the code selected.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function(){
 
        $('#questionQQ .answer_cell_001 option[value=1]').text('No recurro');
        $('#questionQQ .answer_cell_001 option[value=2]').text('Arocena Gustavo');
        $('#questionQQ .answer_cell_001 option[value=3]').text('Aspra Manuel');
        $('#questionQQ .answer_cell_001 option[value=4]').text('Bravo Ricardo');
        $('#questionQQ .answer_cell_001 option[value=5]').text('Zalazar Martin');
 
        $('#questionQQ .answer_cell_002 option[value=1]').text('No recurro');
        $('#questionQQ .answer_cell_002 option[value=2]').text('Bravo Ricardo');
        $('#questionQQ .answer_cell_002 option[value=3]').text('Fernandez Flavio');
        $('#questionQQ .answer_cell_002 option[value=4]').text('Zalazar Martin');
        $('#questionQQ .answer_cell_002 option[value=5]').text('').hide();
 
    });
The administrator has disabled public write access.

Array question with answers in dropdown boxes 1 month 2 weeks ago #143424

  • tpartner
  • tpartner's Avatar
  • Online
  • LimeSurvey Team
  • Posts: 6571
  • Thank you received: 1477
  • Karma: 579
In that case, you would either need to use Expression Manager to pipe in the text depending on the code or use Denis' arrayTextAdapt plugin.
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The administrator has disabled public write access.
Time to create page: 0.462 seconds
Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form