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 9 months ago #57612

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6570
  • Thank you received: 1477
  • Karma: 579
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 9 months ago #57616

  • paulfiner
  • paulfiner's Avatar
  • Offline
  • Expert Lime
  • Posts: 95
  • 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.
Time to create page: 0.358 seconds
Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form