Check out the LimeSurvey source code on GitHub!

Create unique options in array question

More
5 years 10 months ago #57612 by tpartner
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.

Please Log in to join the conversation.

More
5 years 10 months ago #57616 by paulfiner
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

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form