Alternate ranking question - Dynamic answer options

3 months 3 hours ago #159920 by tpartner
tpartner replied the topic: Alternate ranking question - Dynamic answer options
Oh, I see your problem now - the filtering is working but the piping is not. Something in the style declaration is messing with Expression Manager.

Use this script. Note that in the style rules you must leave a space after the opening curly braces and before the closing braces.

<script type="text/javascript" charset="utf-8"> 
	$(document).on('ready pjax:complete',function() {
		// Identify this question
		var thisQuestion = $('#question{QID}');
		// Define some "Choose" text
		var choosetext = 'Please choose...';
		// Number of visible rows
		var rowCount = $('tr.answer-item:visible', thisQuestion).length;
		// Loop through all drop-downs
		$('tr.answer-item select', thisQuestion).each(function(i) {
			// Reset if value is above the number of visible rows
			if($(this).val() > rowCount) {
				$(this).prepend('<option value="">'+choosetext+'</option>').val('');
				checkconditions(this.value,, this.type);
			// Remove all unnecessary options
			$('option', this).filter(function() {
				return this.value > rowCount;
		// Listener on the dropdowns
		$('tr.answer-item select', thisQuestion).on('change', function(e) {
			// Handle non-unique answers
		function handleDuplicates() {
			$('.question-item', thisQuestion).removeClass('duplicate-row');
			$('tr.answer-item select', thisQuestion).each(function(i) {
				if(!$(this).closest('.question-item').hasClass('duplicate-row') && $(this).val() != '') {
					var thisSelect = $(this);
					var selectedValue = $(this).val();
					$('tr.answer-item select', thisQuestion).not(this).each(function(i) {
						if($(this).val() == selectedValue) {
		//Insert new style rules
		var newStyle = '<style type="text/css">\
							.duplicate-row { background-color: #E74C3C; }\
							.duplicate-row .answertext { color: #FFFFFF; }\
		$("head link[rel='stylesheet']").last().after(newStyle);

Working survey attached:

File Attachment:

File Name: limesurvey...0-21.lss
File Size:47 KB

Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

2 months 4 weeks ago #159946 by Gensz78
Gensz78 replied the topic: Alternate ranking question - Dynamic answer options
Thank you so much! It's working beautifully now!


Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!