Welcome, Guest
Username: Password: Remember me

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

'You cannot select this answer twice' But now for colomns 1 year 5 months ago #92443

  • Marieke123
  • Marieke123's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 7
  • Thank you received: 1
  • Karma: 0
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>
The administrator has disabled public write access.

Re: 'You cannot select this answer twice' But now for colomns 1 year 5 months ago #92457

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4072
  • Thank you received: 748
  • Karma: 341
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.
The following user(s) said Thank You: Marieke123

Re: 'You cannot select this answer twice' But now for colomns 1 year 5 months ago #92459

  • Marieke123
  • Marieke123's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 7
  • Thank you received: 1
  • Karma: 0
It works! Thank you very much!
The administrator has disabled public write access.

Re: 'You cannot select this answer twice' But now for colomns 1 year 5 months ago #92528

  • Marieke123
  • Marieke123's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 7
  • Thank you received: 1
  • Karma: 0
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 :)
The administrator has disabled public write access.

Re: 'You cannot select this answer twice' But now for colomns 1 year 5 months ago #92593

  • Marieke123
  • Marieke123's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 7
  • Thank you received: 1
  • Karma: 0
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>
The administrator has disabled public write access.

Re: 'You cannot select this answer twice' But now for colomns 1 year 5 months ago #92594

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4072
  • Thank you received: 748
  • Karma: 341
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.
The following user(s) said Thank You: Marieke123

Re: 'You cannot select this answer twice' But now for colomns 1 year 5 months ago #92595

  • Marieke123
  • Marieke123's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 7
  • Thank you received: 1
  • Karma: 0
Yes this code works! Thank you for your help!
The administrator has disabled public write access.

Re: 'You cannot select this answer twice' But now for colomns 1 year 5 months ago #92618

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 6240
  • Thank you received: 794
  • Karma: 238
Why not use the:
Array by column Question type ?

Denis
The administrator has disabled public write access.

Re: 'You cannot select this answer twice' But now for colomns 1 year 5 months ago #92658

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4072
  • Thank you received: 748
  • Karma: 341
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.150 seconds
Donation Image