Last two exclusive rows numerical matrix

More
9 months 3 weeks ago #218620 by Mon2016
Hi all,

I am asking a question of type matrix of numbers and using the checkboxes.

I tell you that I need to exclude the last two options from each column

That is, if SQ005_A and SQ006_A
are checked, exclude all others SQ001_A SQ002_A SQ003_A SQ004_A

The same happens with column B, C, D

I found something very useful in the forum, but it only works to make the last row exclusive, and I'm looking to make the last two exclusive.

I appreciate your help too much

Attachments:

Please Log in to join the conversation.

More
9 months 3 weeks ago #218633 by tpartner
Err...what did you find?

Cheers,
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.

More
9 months 3 weeks ago #218639 by Mon2016
Hi @tpartner

Thanks for answering,

I found this script:

<script type="text/javascript" charset="utf-8">
$(document).on('ready pjax:scriptcomplete',function(){
 
// Identify this question
var qID = '{QID}';
var thisQuestion = $('#question'+qID);
 
// Assign column-specific attributes and classnames
$('tr.subquestion-list', thisQuestion).each(function(i) {
$('> *', this).each(function(i) {
$(this).attr('data-column', i);
});
});
$('tr.subquestion-list:last td.answer-item', thisQuestion).addClass('exclusive-item');
 
// A function to un-check boxes
function resetCheckbox(thisItem) {
$(':hidden', thisItem).val('');
$(':checkbox', thisItem).prop('checked', false).trigger('change');
}
 
// Listener on the checkboxes
$(':checkbox', thisQuestion).on('change', function(e) {
if($(this).is(':checked')) {
var thisItem = $(this).closest('.answer-item');
var thisColumn = $(thisItem).attr('data-column');
var items = $('td.answer-item[data-column="'+thisColumn+'"].exclusive-item', thisQuestion);
if($(thisItem).hasClass('exclusive-item')) {
items = $('td.answer-item[data-column="'+thisColumn+'"]:not(.exclusive-item)', thisQuestion);
}
$.each(items, function(i, el) {
resetCheckbox(el);
});
}
});
});
</script>

In this post:
forums.limesurvey.org/forum/can-i-do-thi...es-all-others#208856

As I mentioned before, it works very well excluding the last row of options, but I wish it was like this for the last two.

Thanks again. :)

Please Log in to join the conversation.

More
9 months 3 weeks ago #218649 by tpartner
What LimeSurvey version do you use?

Can you attach a small sample survey (.lss file) containing only that question and your JavaScript?

Cheers,
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.

More
9 months 3 weeks ago #218656 by Mon2016
Thanks Tony,

I am attaching the lss survey with the question and the script.

I tell you that I am using 3.25 and 2.50. I ran it in both versions and with the script it works for both versions.

:) :)
Attachments:

Please Log in to join the conversation.

More
9 months 3 weeks ago #218665 by tpartner
This script will render the last two rows of an array-numbers-checkboxes question as exclusive.
 
 
<script type="text/javascript" data-author="Tony Partner">	
	$(document).on('ready pjax:scriptcomplete',function(){
 
		// Identify this question
		var qID = '{QID}';
		var thisQuestion = $('#question'+qID);
 
		// Assign column-specific attributes and classnames
		$('tr.subquestion-list', thisQuestion).each(function(i) {
			$('> *', this).each(function(i) {
				$(this).attr('data-column', i);
			});
		});
		$('tr.subquestion-list', thisQuestion).slice(-2).find('td.answer-item').addClass('exclusive-item');
 
		// A function to un-check boxes
		function resetCheckbox(thisItem) {
			$(':hidden', thisItem).val('');
			$(':checkbox', thisItem).prop('checked', false).trigger('change');
		}
 
		// Listener on the checkboxes
		$(':checkbox', thisQuestion).on('change', function(e) {
			if($(this).is(':checked')) {
				var thisItem = $(this).closest('.answer-item');
				var thisColumn = $(thisItem).attr('data-column');
				var items = $('td.answer-item[data-column="'+thisColumn+'"].exclusive-item', thisQuestion);
				if($(thisItem).hasClass('exclusive-item')) {
					items = $('td.answer-item[data-column="'+thisColumn+'"]', thisQuestion).not(thisItem);
				}
				$.each(items, function(i, el) {
					resetCheckbox(el);
				});
			}
		});
    });
</script>

Sample survey attached: 

File Attachment:

File Name: limesurvey...3221.lss
File Size:26 KB

Cheers,
Tony Partner

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

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now