How to place a certain option at the end of a list with randomized answers

Más
1 año 5 meses antes #165478 por vzyldd
Question type: Array
Limesurvey version: Version 3.5.1+180312

I need to keep the last option in the subquestion list (total of 6 subquestions) last when I randomize option 1 to 5. I found the following script and used it in the question but not working in this version. Any suggestions?

<script type='text/javascript'>
/* Place option 6 at the end of the randomized list */
$(document).ready(function() {
var move_element="6";
/* Please do NOT change the lines below */
var move_element="javatbd{SGQ}"+move_element;
$("#"+move_element).insertAfter("#question{QID} .answers-list .answer-item:last-child");
});
</script>

Por favor, Identificarse o Crear cuenta para unirse a la conversación.

LimeSurvey Partners
Más
1 año 5 meses antes - 1 año 5 meses antes #165485 por tpartner
Add something like this to the question source:

<script type="text/javascript" charset="utf-8">
	$(document).on('ready pjax:complete',function() {
 
		// Define the subquestion code to be fixed at the bottom of the array
		var fixedCode = 'SQ004';
 
		// Move that row to the bottom
		$('#question{QID} table.subquestion-list tbody:eq(0)').append($('tr[id$="X{QID}'+fixedCode+'"]'));
 
		// Fix up the row background colours
		$('#question{QID} tr.answers-list').each(function(i){
			$(this).removeClass('ls-even, ls-odd');
			if(i % 2 == 0) {
				$(this).addClass('ls-even');
			}
			else {
				$(this).addClass('ls-odd');
			}
		});
	});
</script>

Sample survey attached:

Archivo Adjunto:

Nombre del Archivo: limesurvey...9162.lss
Tamaño del Archivo: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
Adjuntos:
Última Edición: 1 año 5 meses antes por tpartner.

Por favor, Identificarse o Crear cuenta para unirse a la conversación.

Más
1 año 5 meses antes #165491 por vzyldd
Thank you Tony. Just what I need.

Por favor, Identificarse o Crear cuenta para unirse a la conversación.

Más
1 mes 1 semana antes #186536 por SabrinaCasanova
Hi,

I tried this script on radio list question but not working in limesurvey 2.57. Please advise.
I want the two option with code 98 and 99 at the end and after the "other" option.
In attachment the survey.

below the script :

<script type='text/javascript'>
/* Place option 98 at the end of the randomized list */
$(document).ready(function() {
var move_element="98";
/* Please do NOT change the lines below */
var move_element="javatbd{SGQ}"+move_element;
$("#"+move_element).insertAfter("#question{QID} .answers-list .answer-item:last-child");
});
</script>
<script type='text/javascript'>
/* Place option 99 at the end of the randomized list */
$(document).ready(function() {
var move_element="99";
/* Please do NOT change the lines below */
var move_element="javatbd{SGQ}"+move_element;
$("#"+move_element).insertAfter("#question{QID} .answers-list .answer-item:last-child");
});
</script>



Thanks
Adjuntos:

Por favor, Identificarse o Crear cuenta para unirse a la conversación.

Más
1 mes 1 semana antes - 1 mes 1 semana antes #186538 por Joffm
Hi, Sabrina

Here you find the scripts for all version (2.06, 2.50-2.73, 3.x)
https://manual.limesurvey.org/Workarounds:_Manipulating_a_survey_at_runtime_using_Javascript#Partially_Randomized_Answers_-_Multiple_Options_.26_List_.28radio.29_questions_.28Enhanced.29

Use this one for LS version 2.50-2.73
<script type="text/javascript" charset="utf-8">	
 
	$(document).ready(function() {
 
		// The number of answers to be fixed at the end of the list
		var fixedAnswers = 2;
 
		// Set this to "true" if you want "Other" to be fixed in the last position
		var otherFixed = false;
 
		// Identify this question
		var qID = {QID}; 
 
		// Find the number of answers
		var ansCount = $('#question'+qID+' .answer-item').length;
		if($('#question'+qID+' input[type="text"]').length > 0) {
			ansCount = ansCount -1
		}
 
		// Place the last n answers created at the end of the list
		var fixedIndex = fixedAnswers - 1;
		for (var i=0; i<fixedAnswers; i++) {
			var answer = $('input[id^="answer"][id$="X'+qID+'s'+(ansCount-fixedIndex)+'"]');
			var answerItem = $(answer).closest('.answer-item');
			var answersList = $(answer).closest('.answers-list');
			if($('#question'+qID).hasClass('multiple-opt')) {
				answer = $('input[id^="answer"][id$="X'+qID+(ansCount-fixedIndex)+'"]');
				answerItem = $(answer).closest('.answer-item').parent();
				answersList = $(answer).closest('.subquestion-list');
			}
			$(answersList).append(answerItem);
			fixedIndex--;
		}		
 
		// Handle "Other"
		if(otherFixed == true && $('#question'+qID+' input[type="text"]').length > 0) {
			var otherAnswer = $('#question'+qID+' input[type="text"]');
			var otherAnswerItem = $(otherAnswer ).closest('.answer-item');
			var otherAnswersList = $(otherAnswer ).closest('.answers-list');
			if($('#question'+qID).hasClass('multiple-opt')) {
				otherAnswerItem = $(otherAnswer ).closest('.answer-item').parent();
				otherAnswersList = $(otherAnswer ).closest('.subquestion-list');
			}
			$(otherAnswersList).append(otherAnswerItem);
		}
	});
</script>



And an example

Archivo Adjunto:

Nombre del Archivo: limesurvey...2319.lss
Tamaño del Archivo:45 KB


Best regards
Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Adjuntos:
Última Edición: 1 mes 1 semana antes por Joffm.
El siguiente usuario dijo gracias: SabrinaCasanova

Por favor, Identificarse o Crear cuenta para unirse a la conversación.

Más
1 mes 1 semana antes #186541 por SabrinaCasanova

Por favor, Identificarse o Crear cuenta para unirse a la conversación.

Más
1 mes 5 días antes #186816 por SabrinaCasanova
Working on Q2 (multiple choice) but not on Q01 and Q1 (single choice) for limesurvey 2.57.1

Please advice

Por favor, Identificarse o Crear cuenta para unirse a la conversación.

Más
1 mes 4 días antes #186819 por Joffm
Hi, Sabrina,
I do not see any issue.
I only can test in Version 2.73.1+171220




As you might have seem in the manual
https://manual.limesurvey.org/Workarounds:_Manipulating_a_survey_at_runtime_using_Javascript#Partially_Randomized_Answers_-_Multiple_Options_.26_List_.28radio.29_questions_.28Enhanced.29
and what I did not:
It is only tested in 2.70, not in earlier versions of this branch.

To check this, please send your survey (only the respective questions) as *.lss
So, we'll see if it's a version problem (meaning you have to update) or something else.
As your version was released in december 2016 you really should consider this.
And if you would like to stay to your used branch (2.50-2.73) you find the latest version here.
https://www.limesurvey.org/downloads/category/24-archived-releases

Best regards
Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Adjuntos:

Por favor, Identificarse o Crear cuenta para unirse a la conversación.

Más
1 mes 4 días antes - 2 semanas 5 días antes #186825 por tpartner
@Joffm, actually that may be broken. If otherFixed = true, then that option should appear at the very end of the list, not second last as in your screenshot.

I'm not in s position to test in the next couple of days but will look into it as soon as possible.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
Última Edición: 2 semanas 5 días antes por tpartner.

Por favor, Identificarse o Crear cuenta para unirse a la conversación.

Más
2 semanas 6 días antes #187278 por SabrinaCasanova
Hi,

I tried with Version 3.17.8+190722 and also not working, please advice.

Thanks

Por favor, Identificarse o Crear cuenta para unirse a la conversación.

Más
2 semanas 5 días antes #187281 por Joffm

and also not working, please advice.

What is not working???
I showed that it worked in 2.60/2.73 (except of Tony's remark)
And here I show it in 3.X
1. "Option 4", "Option 5" and "Other" fixed
2. "Option 4", "Option 5" fixed, but "Other" not fixed




So I advice to
send the respective question(s) as *.lss.

Joffm

How can we try to help without knowing what you are doing?


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Adjuntos:
El siguiente usuario dijo gracias: DenisChenu, tpartner

Por favor, Identificarse o Crear cuenta para unirse a la conversación.

Más
2 semanas 5 días antes #187285 por SabrinaCasanova
Hi,

The fixed options at the end not working for me for two version :

Version 2.57



Version 3.17


Thanks
Adjuntos:

Por favor, Identificarse o Crear cuenta para unirse a la conversación.

Más
2 semanas 5 días antes #187291 por Joffm
Nice to see,
but where is your survey (*.lss)?

And: Are you allowed to run JavaScript?

Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless

Por favor, Identificarse o Crear cuenta para unirse a la conversación.

Más
2 semanas 3 días antes #187434 por SabrinaCasanova
The file lss is already in attachment, here is again. Is there an action to do to activate javascript? I already used javascript code like hide and display elements and it would work well.

Thanks
Adjuntos:

Por favor, Identificarse o Crear cuenta para unirse a la conversación.

Más
2 semanas 2 días antes #187444 por Joffm
Hi, you sent a survey, but didn't say for which version.
You see, the javascript is a bit different.

Okay, here you get two samples
1. 2.50/2.73

Archivo Adjunto:

Nombre del Archivo: limesurvey...V273.lss
Tamaño del Archivo:46 KB


2. 3.x

Archivo Adjunto:

Nombre del Archivo: limesurvey..._V3x.lss
Tamaño del Archivo:32 KB


And some screenshots
V 2.50/2.73



V 3.x



Volunteers are not paid.
Not because they are worthless, but because they are priceless
Adjuntos:

Por favor, Identificarse o Crear cuenta para unirse a la conversación.

¡Comenzar ahora!

Simplemente cree una cuenta y comience a usar LimeSurvey hoy mismo.

Registrarse ahora
¡Únase a nuestro boletín informativo!

Iniciar sesión