Welcome, Guest
Username: Password: Remember me

TOPIC: Randomize order BUT keeping 2 elements always together?

Randomize order BUT keeping 2 elements always together? 1 year 5 months ago #87428

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!
The administrator has disabled public write access.

Re: Randomize order BUT keeping 2 elements always together? 1 year 5 months ago #87687

  • paulfiner
  • paulfiner's Avatar
  • OFFLINE
  • Expert Lime
  • Posts: 92
  • Thank you received: 1
  • Karma: 1
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?
The administrator has disabled public write access.

Re: Randomize order BUT keeping 2 elements always together? 1 year 5 months ago #87843

Have you guys figured it out yet?
I have similar situation wherein I would like to anchor the last statement.

Cheers,
Mark.
The administrator has disabled public write access.

Re: Randomize order BUT keeping 2 elements always together? 1 year 5 months ago #87844

  • paulfiner
  • paulfiner's Avatar
  • OFFLINE
  • Expert Lime
  • Posts: 92
  • Thank you received: 1
  • Karma: 1
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>
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.146 seconds
Donation Image