Welcome, Guest
Username: Password: Remember me

TOPIC: Create unique options in array question

Re: Create unique options in array question 3 years 4 months ago #57612

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4050
  • Thank you received: 740
  • Karma: 341
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.

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: Create unique options in array question 3 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.123 seconds
Donation Image