Willkommen, Gast
Benutzername: Passwort: Angemeldet bleiben:

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

'You cannot select this answer twice' But now for colomns 1 Jahr 5 Monate her #92443

  • Marieke123
  • Marieke123s Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 7
  • Dank erhalten: 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>
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: 'You cannot select this answer twice' But now for colomns 1 Jahr 5 Monate her #92457

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 4071
  • Dank erhalten: 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.
Der Administrator hat öffentliche Schreibrechte deaktiviert.
Folgende Benutzer bedankten sich: Marieke123

Re: 'You cannot select this answer twice' But now for colomns 1 Jahr 5 Monate her #92459

  • Marieke123
  • Marieke123s Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 7
  • Dank erhalten: 1
  • Karma: 0
It works! Thank you very much!
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: 'You cannot select this answer twice' But now for colomns 1 Jahr 5 Monate her #92528

  • Marieke123
  • Marieke123s Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 7
  • Dank erhalten: 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 :)
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: 'You cannot select this answer twice' But now for colomns 1 Jahr 5 Monate her #92593

  • Marieke123
  • Marieke123s Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 7
  • Dank erhalten: 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>
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: 'You cannot select this answer twice' But now for colomns 1 Jahr 5 Monate her #92594

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 4071
  • Dank erhalten: 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.
Der Administrator hat öffentliche Schreibrechte deaktiviert.
Folgende Benutzer bedankten sich: Marieke123

Re: 'You cannot select this answer twice' But now for colomns 1 Jahr 5 Monate her #92595

  • Marieke123
  • Marieke123s Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 7
  • Dank erhalten: 1
  • Karma: 0
Yes this code works! Thank you for your help!
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: 'You cannot select this answer twice' But now for colomns 1 Jahr 5 Monate her #92618

  • DenisChenu
  • DenisChenus Avatar
  • OFFLINE
  • Moderator Lime
  • Beiträge: 6236
  • Dank erhalten: 794
  • Karma: 238
Why not use the:
Array by column Question type ?

Denis
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: 'You cannot select this answer twice' But now for colomns 1 Jahr 5 Monate her #92658

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 4071
  • Dank erhalten: 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.
Der Administrator hat öffentliche Schreibrechte deaktiviert.
Moderatoren: ITEd
Ladezeit der Seite: 0.171 Sekunden
Donation Image