Bienvenue, Invité
Nom d'utilisateur : Mot de passe : Se souvenir de moi

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

'You cannot select this answer twice' But now for colomns il y a 1 an 9 mois #92443

  • Marieke123
  • Portrait de Marieke123
  • Hors ligne
  • Fresh Lemon
  • Messages : 7
  • Remerciements reçus 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>
L'administrateur a désactivé l'accès en écriture pour le public.

Re: 'You cannot select this answer twice' But now for colomns il y a 1 an 9 mois #92457

  • tpartner
  • Portrait de tpartner
  • Hors ligne
  • LimeSurvey Team
  • Messages : 4371
  • Remerciements reçus 829
  • Karma: 381
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.
L'administrateur a désactivé l'accès en écriture pour le public.
Cet utilisateur a été remercié pour son message par: Marieke123

Re: 'You cannot select this answer twice' But now for colomns il y a 1 an 9 mois #92459

  • Marieke123
  • Portrait de Marieke123
  • Hors ligne
  • Fresh Lemon
  • Messages : 7
  • Remerciements reçus 1
  • Karma: 0
It works! Thank you very much!
L'administrateur a désactivé l'accès en écriture pour le public.

Re: 'You cannot select this answer twice' But now for colomns il y a 1 an 9 mois #92528

  • Marieke123
  • Portrait de Marieke123
  • Hors ligne
  • Fresh Lemon
  • Messages : 7
  • Remerciements reçus 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 :)
L'administrateur a désactivé l'accès en écriture pour le public.

Re: 'You cannot select this answer twice' But now for colomns il y a 1 an 9 mois #92593

  • Marieke123
  • Portrait de Marieke123
  • Hors ligne
  • Fresh Lemon
  • Messages : 7
  • Remerciements reçus 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>
L'administrateur a désactivé l'accès en écriture pour le public.

Re: 'You cannot select this answer twice' But now for colomns il y a 1 an 9 mois #92594

  • tpartner
  • Portrait de tpartner
  • Hors ligne
  • LimeSurvey Team
  • Messages : 4371
  • Remerciements reçus 829
  • Karma: 381
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.
L'administrateur a désactivé l'accès en écriture pour le public.
Cet utilisateur a été remercié pour son message par: Marieke123

Re: 'You cannot select this answer twice' But now for colomns il y a 1 an 9 mois #92595

  • Marieke123
  • Portrait de Marieke123
  • Hors ligne
  • Fresh Lemon
  • Messages : 7
  • Remerciements reçus 1
  • Karma: 0
Yes this code works! Thank you for your help!
L'administrateur a désactivé l'accès en écriture pour le public.

Re: 'You cannot select this answer twice' But now for colomns il y a 1 an 9 mois #92618

  • DenisChenu
  • Portrait de DenisChenu
  • Hors ligne
  • Moderator Lime
  • Messages : 6551
  • Remerciements reçus 869
  • Karma: 257
Why not use the:
Array by column Question type ?

Denis
L'administrateur a désactivé l'accès en écriture pour le public.

Re: 'You cannot select this answer twice' But now for colomns il y a 1 an 9 mois #92658

  • tpartner
  • Portrait de tpartner
  • Hors ligne
  • LimeSurvey Team
  • Messages : 4371
  • Remerciements reçus 829
  • Karma: 381
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.
L'administrateur a désactivé l'accès en écriture pour le public.
Modérateurs: ITEd
Temps de génération de la page : 0.160 secondes
Donation Image