Check out the LimeSurvey source code on GitHub!
Welcome, Guest
Username: Password:

TOPIC: Create unique options in array question

Create unique options in array question 5 years 4 months ago #57612

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6129
  • Thank you received: 1360
  • Karma: 535
Try this as the complete script:
<script type="text/javascript" charset="utf-8">
	$(document).ready(function() {
 
		var qID = 2326;
 
		$('#question'+qID+' table.question tbody td').click(function () { 
		    var cellClass = $(this).attr('class');
			var parent = $(this).parent();
			setTimeout(function() { 
				if($('.'+cellClass+' input[type=radio]:checked').length > 1) {
					$('.'+cellClass+' input[type=radio]').attr('checked', false);
					$('.'+cellClass+' input[type=radio]', parent).attr('checked', true); 
				}
			}, 250);
		});
 
		// Interrupt the submit function and check each column for a checked radio
		$('form#limesurvey').submit(function(){
 
			var warningText = 'Please answer 3 to continue';
			var ok = 1;
 
			$('#question'+qID+' table.question tbody:first td').each(function(i) { 
				var colClass = $(this).attr('class');
				if($('.'+colClass+' input.radio:checked').length < 1) {
					ok = 0;
				}
			});
			if(ok == 0) {
				alert (warningText);
				return false;
			}
			else {
				return true;
			}
 		});
	});
 
</script>
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The administrator has disabled public write access.

Create unique options in array question 5 years 4 months ago #57616

  • paulfiner
  • paulfiner's Avatar
  • Offline
  • Expert Lime
  • Posts: 92
  • Thank you received: 1
  • Karma: 1
Many thanks for all your help with this Tony.
I now have it working 100% although not using your last bit of code.

I just have a simple loop that goes through all the radiobuttons and keeps a running total of the checked ones. If this equals 3 then I proceed otherwise I show an alert.

Cheers

Paul
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.196 seconds
Imprint                   Data Protection Statement                  Revocation information and revocation form