Welcome, Guest
Username: Password: Remember me

TOPIC: Single choice in array

Single choice in array 2 years 10 months ago #70747

  • misterdot
  • misterdot's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 35
  • Thank you received: 1
  • Karma: 0
I have a survey that needs a grid where the user can select only one choice:

choice1 choice2 choice3
Male
Female

I've tried it as an array, array by column, etc, but if the user accidentally checks the wrong gender, they can't clear the choice. Is there a way to set this up? I've attached a sample survey in case it's useful.
Thanks,
Matt
Attachments:
The administrator has disabled public write access.

Re: Single choice in array 2 years 10 months ago #70756

  • atiut
  • atiut's Avatar
  • OFFLINE
  • Senior Lime
  • Posts: 76
  • Thank you received: 2
  • Karma: 1
What you want is essentially a single-option question.

So you can combine your labels as follows

male - choice 1
male - choice 2
...
female - choice 3

then choose a layout on 2 columns (male/female) or maybe 3 columns (choice 1 to 3).

I admit this is a suboptimal solution. Maybe someone can provide better :).
The administrator has disabled public write access.

Re: Single choice in array 2 years 10 months ago #70759

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4267
  • Thank you received: 803
  • Karma: 368
Here's a simple script to allow only one radio in an Array question to be checked.

1) Set up your survey to use JavaScript.

2) Add the following script to the source of the array. Replace "QQ" with the array question ID.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function(){
 
		var qID = QQ;
 
		// Listener on radio buttons to allow only one checked
		$('#question'+qID+' .question input.radio').click(function(){
 
			$('#question'+qID+' input.radio:checked').attr('checked', false);
		});
 
		// Listener on radio cells to allow only one checked
		$('#question'+qID+' .question tbody td').click(function(){
 
			$('#question'+qID+' input.radio:checked').attr('checked', false);
			$('input.radio', this).attr('checked', true);
		});
	});
 
</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.
Last Edit: 2 years 10 months ago by tpartner.
The administrator has disabled public write access.

Re: Single choice in array 2 years 10 months ago #70769

  • misterdot
  • misterdot's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 35
  • Thank you received: 1
  • Karma: 0
Thanks to you both. Tony, that appears to be exactly what I need, however when I select any choice, it checks the last radial button in both rows and doesn't let me change the selection (for either row). I've attached a screenshot.
Attachments:
The administrator has disabled public write access.

Re: Single choice in array 2 years 10 months ago #70770

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4267
  • Thank you received: 803
  • Karma: 368
That's odd, I have tested this in IE and FireFox and other users have had success with it. Can you activate a sample survey for me to test?
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.

Re: Single choice in array 2 years 10 months ago #70772

  • misterdot
  • misterdot's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 35
  • Thank you received: 1
  • Karma: 0
Yep, here you go:
dms.sph.sc.edu/limesurvey/index.php?sid=74898&lang=en
I've been testing in Chrome, but just tried FF and IE and it's the same.
Here's my question script. qID is just the question ID and not the full SGQA, correct?
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function(){
 
		var qID = 794;
 
		// Listener on radio buttons to allow only one checked
		$('#question'+qID+' .question input.radio').click(function(){
 
			$('#question'+qID+' input.radio:checked').attr('checked', false);
		});
 
		// Listener on radio cells to allow only one checked
		$('#question'+qID+' .question tbody td').click(function(){
 
			$('#question'+qID+' input.radio:checked').attr('checked', false);
			$('input.radio', this).attr('checked', true);
		});
	});
 
</script>
The administrator has disabled public write access.

Re: Single choice in array 2 years 10 months ago #70774

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4267
  • Thank you received: 803
  • Karma: 368
Ah, it's because you are using a copy of the bluengrey template which has divs with a class of "question" as well as the array questions having tables with a class of "question" and I wasn't specific enough with my selectors - sorry.

Use this:
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function(){
 
		var qID = QQ;
 
		// Listener on radio buttons to allow only one checked
		$('#question'+qID+' table.question input.radio').click(function(){
 
			$('#question'+qID+' input.radio:checked').attr('checked', false);
		});
 
		// Listener on radio cells to allow only one checked
		$('#question'+qID+' table.question tbody td').click(function(){
 
			$('#question'+qID+' input.radio:checked').attr('checked', false);
			$('input.radio', this).attr('checked', true);
		});
	});
 
 
</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.

Re: Single choice in array 2 years 10 months ago #70775

  • misterdot
  • misterdot's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 35
  • Thank you received: 1
  • Karma: 0
That was it -- thanks!
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.119 seconds
Donation Image