Dual Scale - Allow to either answer on both scales or neither

3 years 11 months ago #124273 by tillB
Hey Limes,

i have a survey with a lot of Dual Scale questions. I would like to know, if it is possible that participants can either give an answer on both scales or on none. To clarifiy: i dont want to make the question required, only if they answer any question on one of the two scales, they also would have to give an answer on the other scale.

If there is no Limesurvey feature for that and a js solution is necessary, i have another question :D. Since i have a lot of questions, i would like to know, if there is a way to get a list of all questionIDs of all dual scale questions, so i dont have to go through every question and copy the id out myself in order to apply javascript to all of them.

Thanks a lot for your help in advance, i really appreciate it!

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

LimeSurvey Partners
3 years 11 months ago - 3 years 11 months ago #124337 by tpartner
You can achieve this behaviour with JavaScript:

1) Place this small plugin at the end of template.js. The plugin interrupts the next/submit process and checks for rows with single answers. If found, a class is applied to that row, an alert is popped up and the next/submit process is aborted.
	// A jQuery plugin ensure that there are no rows with single answers
	(function( $ ){
		$.fn.lsHandleArray = function(options) {  
			var opts = $.extend( {
				alertText: 'Please complete the indicated rows.'
			}, options);
			return this.each(function() { 
				var thisQuestion = $(this);
				// Interrupt the Next/Submit click
				$('#movenextbtn, #movesubmitbtn').bind('click', function () {
					// Reset
					$('tr.answers-list', thisQuestion).removeClass('invalid-answer');
					// Loop through the array rows
					$('tr.answers-list', thisQuestion).each(function(i) {
						if($('input.radio:checked', this).length == 1) {
					// Pop up alert and abort submit if invalid rows found
					if($('tr.invalid-answer', thisQuestion).length > 0) {
						$('#movenextbtn, #movesubmitbtn').blur();
						return false;
	})( jQuery );

2) Place something like this at the end of template.css to highlight the invalid rows.
tr.invalid-answer {
	background: pink;

3) Place this in the source of every question you want to apply the plugin to:
<script type="text/javascript" charset="utf-8">		
	$(document).ready(function() {	
		$('#question{QID}').lsHandleArray({alertText: 'Please complete the indicated rows.'});

Regarding your question about finding all of the array-dual-scale questions - you can search the Survey Logic File for all instances of "Array dual scale".

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: 3 years 11 months ago by tpartner.

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

3 years 11 months ago #124354 by tillB
Thanks a lot for that solution, tpartner!

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!