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

More
1 year 5 months ago #165478 by 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>

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

LimeSurvey Partners
More
1 year 5 months ago - 1 year 5 months ago #165485 by 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:

File Attachment:

File Name: limesurvey...9162.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:
Last edit: 1 year 5 months ago by tpartner.

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

More
1 year 5 months ago #165491 by vzyldd
Thank you Tony. Just what I need.

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

More
1 month 1 week ago #186536 by 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
Attachments:

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

More
1 month 1 week ago - 1 month 1 week ago #186538 by 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

File Attachment:

File Name: limesurvey...2319.lss
File Size:45 KB


Best regards
Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:
Last edit: 1 month 1 week ago by Joffm.
The following user(s) said Thank You: SabrinaCasanova

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

More
1 month 1 week ago #186541 by SabrinaCasanova

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

More
1 month 5 days ago #186816 by SabrinaCasanova
Working on Q2 (multiple choice) but not on Q01 and Q1 (single choice) for limesurvey 2.57.1

Please advice

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

More
1 month 4 days ago #186819 by 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
Attachments:

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

More
1 month 4 days ago - 2 weeks 5 days ago #186825 by 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
Last edit: 2 weeks 5 days ago by tpartner.

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

More
2 weeks 6 days ago #187278 by SabrinaCasanova
Hi,

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

Thanks

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

More
2 weeks 5 days ago #187281 by 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
Attachments:
The following user(s) said Thank You: DenisChenu, tpartner

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

More
2 weeks 5 days ago #187285 by SabrinaCasanova
Hi,

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

Version 2.57



Version 3.17


Thanks
Attachments:

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

More
2 weeks 5 days ago #187291 by 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

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

More
2 weeks 3 days ago #187434 by 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
Attachments:

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

More
2 weeks 2 days ago #187444 by 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

File Attachment:

File Name: limesurvey...V273.lss
File Size:46 KB


2. 3.x

File Attachment:

File Name: limesurvey..._V3x.lss
File Size: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
Attachments:

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!