Quantcast
Channel: Topics in Category: Can I do this with LimeSurvey? - LimeSurvey forums
Viewing all articles
Browse latest Browse all 17529

Randomize two sets of answer choices - by: tpartner

$
0
0
Here is a JavaScript solution to randomly invert all except the last answer within a single question.

Set up your survey to use JavaScript and place the following script in the source of the question:

<script type="text/javascript" charset="utf-8">
	$(document).ready(function(){
 
		// Identify this question
		var qID = {QID};
		var thisQuestion = $('#question'+qID);
 
		// Generate random number between 1 & 2
		var rand = Math.floor(Math.random() * 2) + 1
 
		// If the random number = 2...
		if(rand == 2) {
			// Reverse the answer order (excepting the last answer)
			var lastAnswer = $('.answer-item:last', thisQuestion);
			var tr = $('.answer-item', thisQuestion).not(lastAnswer).detach().toArray();
			tr.reverse();
			$.each(tr, function(i, el) {
				$('.answers-list', thisQuestion).append(el);
			});
			$('.answers-list', thisQuestion).append(lastAnswer);
		}
	});
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey_survey_8858861_2017-08-14.lss
File Size: 15 KB

Viewing all articles
Browse latest Browse all 17529

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>