Array filter between Scale 1 and Scale 2 in Dual Matrix - with Dropdown-Menue

More
3 years 7 months ago #118881 by boriginal
boriginal created the topic: Array filter between Scale 1 and Scale 2 in Dual Matrix - with Dropdown-Menue
Hey Lemons,

Some weeks ago I ask in this forum how to set an array filter between scale 1 and scale 2 in a dual matrix and got perfect help:

Array filter between Scale 1 and Scale 2 in Dual Matrix

Now I would like to do the same with a dual matrix with dropdown menues. I tried to adjust the script, but without success. Can you please tell me, if it is possible to disable the dropdown menue in scale 2 dependendly from the answer in scale 1?

I want to disable the second scale if the participant chooses the last option in the dropdown menue in scale 1. To set the second menue to a given answer dependently from the choice in scale 1 is also fine.

Thank you very much!

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

More
3 years 7 months ago - 3 years 7 months ago #118887 by tpartner
tpartner replied the topic: Array filter between Scale 1 and Scale 2 in Dual Matrix - with Dropdown-Menue
Placing this script in the question source will result in the following behaviour:
- When selecting the last option in a scale-1 drop-down, the scale-2 drop-down in that row will also be set to its last option and disabled.
- Selecting any but the last option in a scale-1 drop-down will enable the scale-2 drop-down in that row.

<script type="text/javascript" charset="utf-8">	
	$(document).ready(function() {
 
		// Identify this question
		var thisQuestion = $('#question{QID}');
 
		// Assign classes
		$('tr.subquestion-list', thisQuestion).each(function(i){
			$('td.answer-item', this).each(function(i){
				$(this).addClass('scale-'+(i+1));
			});
		});
 
		// Some vars...
		var excludeValue1 = $('td.answer-item:eq(0) option:last', thisQuestion).attr('value');
		var excludeValue2 = $('td.answer-item:eq(1) option:last', thisQuestion).attr('value');
 
		// Listener on the dropdowns
		$('.scale-1 select', thisQuestion).change(function(e) {
			var thisRow = $(this).closest('tr');
			if($(this).val() == excludeValue1) {
				$('.scale-2 select', thisRow).val(excludeValue2).prop('disabled', true);
			}
			else if($('.scale-2 select', thisRow).is(':disabled')){
				$('.scale-2 select', thisRow).prop('disabled', false);
			}
		});
 
		// Initial states
		$('.scale-1 select', thisQuestion).each(function(i) {
			var thisRow = $(this).closest('tr');
			if($(this).val() == excludeValue1) {
				$('.scale-2 select', thisRow).val(excludeValue2).prop('disabled', true);
			}
		});
 
		// Remove any "disabled" properties befor submitting
		$('#movenextbtn, #movesubmitbtn').bind('click', function () {			
			$('select', thisQuestion).prop('disabled', false);
		});
 
    });	
</script>

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last Edit: 3 years 7 months ago by tpartner.
The following user(s) said Thank You: boriginal

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

More
3 years 7 months ago #118892 by boriginal
boriginal replied the topic: Array filter between Scale 1 and Scale 2 in Dual Matrix - with Dropdown-Menue
Thank you! This is all I ever want! It works perfectly.

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!