Check out the LimeSurvey source code on GitHub!

'You cannot select this answer twice' But now for colomns

More
4 years 1 week ago #92443 by Marieke123
Dear Limesurvey pro’s!
I use LimeSurvey Version 1.92+ Build 120319
I have an array question in my survey. It looks like this:
Treatment 1 Treatment 2 Treatment 3
Most attractive treatment 0 0 0
Least attractive treatment 0 0 0

The restriction I want to get in the source code. Is that the respondent cannot chose the same treatment for both rows. A treatment cannot be most and least attractive. I want an error like ‘you cannot select this answer twice’.

Now I looked in the workarounds for maxdiff questions and I found the following script, but unfortunately it is not as simple as replacing clickRow with clickColumn.
Can somebody help me fixing this problem?

<script type="text/javascript" charset="utf-8">

$(document).ready(function(){

maxDiff(QQ, 'You cannot select this answer twice.');

function maxDiff(qID, msg) {

// Prevent clicking twice in the same row
$('#question'+qID+' input.radio').mousedown(function () {
var clickRow = $(this).parents('tr:eq(0)');
if ($('input.radio:checked', clickRow).length > 0) {
alert (msg);
return false;
}
});
$('#question'+qID+' table.question tbody td').mousedown(function () {
var clickRow = $(this).parents('tr:eq(0)');
if ($('input.radio:checked', clickRow).length > 0) {
alert (msg);
return false;
}
});
}

});

</script>

Please Log in to join the conversation.

More
4 years 1 week ago #92457 by tpartner
Try this :
<script type="text/javascript" charset="utf-8">
	$(document).ready(function(){
 
		onePerColumn({QID}, 'You cannot select this answer twice.');
 
		function onePerColumn(qID, msg) {
 
			$('#question'+qID+' table.question tbody tr td').click(function () {
				var columnClass = $(this).attr('class').split(' ')[0];
				if ($('.'+columnClass+' input.radio:checked').length > 1) {
					alert (msg);
					$('input.radio:checked', this).attr('checked', false);
				}
			});
		}
 
	});
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: Marieke123

Please Log in to join the conversation.

More
4 years 1 week ago #92459 by Marieke123
It works! Thank you very much!

Please Log in to join the conversation.

More
4 years 1 week ago #92528 by Marieke123
Okay, I thought it worked well. It certainly does when you only use one array per page/group. But I have several arrays within a group and they are on the same page. And the restriction concerns all arrays instead of one array. So people run out of options because all options are used within previous questions. I need a script that starts all over again within each array on the same group/page. So that for each question/array the respondent has the choice between treatment 1, 2 or 3. But one treatment cannot be chosen as least and most attractive in one array.

So can you please help me one more time :)

Please Log in to join the conversation.

More
4 years 1 week ago #92593 by Marieke123
I'm still facing the problem above, I read from another maxdiff topic on this forum that I should place the code in one question (from the 4 questions on a page) and add the question codes of the other questions to this code. So something like this.
So I have the code beneath in question 1 and the other 3 questions have no code. But unfortunately it still not works... What am I doing wrong?
/><script type="text/javascript" charset="utf-8">
	$(document).ready(function(){
 
		onePerColumn({14456}, 'You cannot select this anwer twice.');
		onePerColumn({14459}, 'You cannot select this anwer twice.');
		onePerColumn({14462}, 'You cannot select this anwer twice.');
		onePerColumn({14465}, 'You cannot select this anwer twice.');
 
 		function onePerColumn(qID, msg) {
 
			$('#question'+qID+' table.question tbody tr td').click(function () {
				var columnClass = $(this).attr('class').split(' ')[0];
				if ($('.'+columnClass+' input.radio:checked').length > 1) {
					alert (msg);
					$('input.radio:checked', this).attr('checked', false);
				}
			});
		}
 
	});
</script>

Please Log in to join the conversation.

More
4 years 1 week ago #92594 by tpartner
Try this:
<script type="text/javascript" charset="utf-8">
	$(document).ready(function(){
 
		onePerColumn({14456}, 'You cannot select this anwer twice.');
		onePerColumn({14459}, 'You cannot select this anwer twice.');
		onePerColumn({14462}, 'You cannot select this anwer twice.');
		onePerColumn({14465}, 'You cannot select this anwer twice.');
 
 		function onePerColumn(qID, msg) {
 
			$('#question'+qID+' table.question tbody tr td').click(function () {
				var columnClass = $(this).attr('class').split(' ')[0];
				if ($('#question'+qID+' .'+columnClass+' input.radio:checked').length > 1) {
					alert (msg);
					$('input.radio:checked', this).attr('checked', false);
				}
			});
		}
 
	});
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: Marieke123

Please Log in to join the conversation.

More
4 years 1 week ago #92595 by Marieke123
Yes this code works! Thank you for your help!

Please Log in to join the conversation.

More
4 years 1 week ago #92618 by DenisChenu
Why not use the:
Array by column Question type ?

Denis

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).

Please Log in to join the conversation.

More
4 years 1 week ago #92658 by tpartner

Why not use the: Array by column Question type ?

Because then a respondent could check more than one radio per row (same problem but transposed).

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.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form