Randomize order BUT keeping 2 elements always together?

More
4 years 10 months ago #87428 by spacejanitor
spacejanitor created the topic: Randomize order BUT keeping 2 elements always together?
Got an interesting problem here and wondering if I can implement it without using complex JS.

If I have a multiple choice question with 5 choices and I want to randomize them, BUT I want to keep elements 4 and 5 always together... what are my options?

So, for example (two possible randomizations):
3
1
4
5
2

or...

2
4
5
1
3


Subsequent questions should maintain this randomization order as well, which is perhaps a separate issue.

I'm a call centre and market research technology consultant, lead/sample provider, and panel broker.

I'm also the co-founder and former IT Director of Winning Research Ltd. - LimeSurvey helped the company become a multi-million dollar company within just a few years!

Please Log in to join the conversation.

More
4 years 10 months ago #87687 by paulfiner
paulfiner replied the topic: Randomize order BUT keeping 2 elements always together?
Did you ever find a solution to this?

I need something similar to this ie. I need to randomise the answers apart from the last 2 which, in my case, are 'Don't know' and 'None of these'.

Any javascript solution?

Please Log in to join the conversation.

More
4 years 10 months ago #87843 by StuartMark0
StuartMark0 replied the topic: Randomize order BUT keeping 2 elements always together?
Have you guys figured it out yet?
I have similar situation wherein I would like to anchor the last statement.

Cheers,
Mark.

Please Log in to join the conversation.

More
4 years 10 months ago #87844 by paulfiner
paulfiner replied the topic: Randomize order BUT keeping 2 elements always together?
I had problems getting the workarounds to work but I managed to get it work using my limited knowledge of Javascript and various Google searches.

Using the code below you just need to change the codes in the variable ansCodesList to match the codes you want to randomise and then add any others that you want to remain fixed, two in my case.
This works on a multi-choice type question but not sure about a radio list type.
<script type="text/javascript" charset="utf-8">
	$(document).ready(function() {
 
		var ansCodesList = [1,2,3,4,5,6];
 
		ansCodesList.sort(function() {return 0.5 - Math.random()})
 
		ansCodesList.push(7);
		ansCodesList.push(8);
 
		// The multi-opt id
		var multiOptID = $('.multiple-opt').attr('id').split('question')[1];
 
		var answersParent = $('.multiple-opt li[id^="javatbd"]:eq(0)').parent();
 
		// Change the order of the multi-opt answers
		$(ansCodesList).each(function(i){
			$(answersParent).append($('.multiple-opt li[id$="'+multiOptID+this+'"]'))
		});
	});
</script>

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now