Last Option In Array (Numbers) (Checkboxes) Column Excludes All Others

More
3 years 5 months ago #131738 by tarantel999
There was a good solution for using exclusive option in checkbox array with forcing the last row to act as exclusive. Is there an easy fix to make it work in columns? So the last row would have exclusive options for the whole column?

Solution for exclusion in rows:
www.limesurvey.org/forum/can-i-do-this-w...-excludes-all-others

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

More
3 years 5 months ago #131746 by tpartner
What version of LimeSurvey are you using?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com

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

More
3 years 5 months ago #131747 by tarantel999
2.05 mostly, tried 2.50 today hoping that it would solve it :)

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

More
3 years 5 months ago #131748 by tpartner
Okay, this should work for 2.05 - 2.50.

<script type="text/javascript" charset="utf-8">		
	$(document).ready(function() {	
 
		// Identify this question
		var thisQuestion = $('#question{QID}');
 
		// Assign row-specific classes
		$('tr.subquestions-list:not(:last) td.question-item', thisQuestion).addClass('non-exclusive');
		$('tr.subquestions-list:last td.question-item', thisQuestion).addClass('exclusive');	
		// Assign column-specific classes
		$('tr.subquestions-list', thisQuestion).each(function(i){
			$('> *', this).each(function(i){
				$(this).addClass('column-'+i+'');
				$(this).attr('data-column', i);
			});
		});	
 
		// Listener on the checkboxes
		$('input[type="checkbox"]', thisQuestion).on('change', function(e) {
 
			if($(this).is(':checked')) {
				var columnNum = $(this).closest('td').attr('data-column');
				if($(this).closest('td').hasClass('exclusive')) {
					$('td[data-column="'+columnNum+'"].non-exclusive input[type="checkbox"]', thisQuestion).prop('checked', false);
					$('td[data-column="'+columnNum+'"].non-exclusive input:hidden', thisQuestion).attr('value', '');
				}
				else {
					$('td[data-column="'+columnNum+'"].exclusive input[type="checkbox"]', thisQuestion).prop('checked', false);
					$('td[data-column="'+columnNum+'"].exclusive input:hidden', thisQuestion).attr('value', '');
				}
 
				// Check relevance
				$('td[data-column="'+columnNum+'"] input[id^="answer"]', thisQuestion).each(function(i) {
					fixnum_checkconditions($(this).attr('value'), $(this).attr('id').replace(/answer/, ''), 'hidden');
				});
			}
		});
    });
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...-5-6.lss
File Size:19 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
Attachments:

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

More
3 years 5 months ago #131814 by tarantel999

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!