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

Array prefilled based on previous array - by: tpartner

$
0
0
In my opinion you logic will is flawed because you can still enter a lower language level now than when you started.

Having said that, placing this script in the source of the first question will meet your requirements.

<script type="text/javascript" charset="utf-8">
	$(document).on('ready pjax:scriptcomplete',function(){
 
		// Identify the questions
		var q1ID = {QID};
		var q1 = $('#question'+q1ID);
		var q2ID = $(q1).nextAll('.array-flexible-row:eq(0)').attr('id').replace(/question/, '');
		var q2 = $('#question'+q2ID);
		var q3ID = $(q1).nextAll('.array-flexible-row:eq(1)').attr('id').replace(/question/, '');
		var q3 = $('#question'+q3ID);
		var arrays = $(q1).add(q2).add(q3);
 
		// Assign column-specific classes
		$('table.subquestion-list tr', arrays).each(function(i) { 
			$('> *:gt(0)', this).each(function(i){
				$(this).addClass('column-'+(i+1));
			});
		});
 
		// Default answers in Q1 
		$('table.subquestion-list tr.answers-list', q1).each(function(i) { 
			if($('input[type="radio"]:checked', this).length == 0) {
				$('input[type="radio"]:first', this).trigger('click');
			}
		});
 
		// Listener on the Q1 radios 
		$('input[type="radio"]', q1).on('click', function(i) {
			handleRadios(this);
		}); 
		$('input[type="radio"]', q2).on('click', function(i) {
			handleRadios(this);
		});
 
		function handleRadios(el) {
			var thisQID = $(el).closest('.array-flexible-row').attr('id').replace(/question/, '');
			var nextQID = $(el).closest('.array-flexible-row').nextAll('.array-flexible-row:eq(0)').attr('id').replace(/question/, '');
			var thisSQCode = $(el).attr('name').split('X'+thisQID)[1];
			var thisQCode = $(el).val();
			var nextCol1Radio = $('tr[id$="X'+nextQID+thisSQCode+'"] .column-1 input[type="radio"]');
			var nextThisRadio = $('tr[id$="X'+nextQID+thisSQCode+'"] input[type="radio"][value="'+thisQCode+'"]');
			if(!$(el).closest('td').hasClass('column-1')) {
				// Disable column-1 in the next question
				$(nextCol1Radio).prop('checked', false).prop('disabled', true);
				// Trigger the corresponding radio in the next question
				$(nextThisRadio).trigger('click');
			}
			else {
				// Enable column-1 in the next question
				$(nextCol1Radio).prop('disabled', false);
			}
		}
	});
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey_survey_2887951.lss
File Size: 28 KB

Viewing all articles
Browse latest Browse all 17529


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