Require multiple answers of a specific option in an array?

More
5 years 2 months ago #75556 by malberghini
malberghini replied the topic: Require multiple answers of a specific option in an array?
Here it is.
Attachments:

Please Log in to join the conversation.

More
5 years 2 months ago #75559 by tpartner
tpartner replied the topic: Require multiple answers of a specific option in an array?
Okay, this code will check the last options by default and disable the "Next" button until at least 2 column-1 answers are checked.

Note: This code is for a single array on a page but could be modified for more than one on a page.

Set up your survey to use JavaScript and add this script to the source of the array.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() { 
 
 
		// Add some column-specific classes
		$('.array-flexible-row table.question tbody tr').each(function(i, el){
			$('> *', this).each(function(i, el){ 
				$(el).addClass('col-'+i);
			});
		});
 
		// Disable the "Next button if less than 2 checked in the first column
		if($('.col-1 input.radio:checked').length < 2) {
			$('#movenextbtn').attr('disabled', true);
		}
 
		// Default check the last option in each row
		$('.array-flexible-row table.question tbody').each(function(i){
			if($('input.radio:checked', this).length == 0) {
				$('input.radio:last', this).attr('checked', true);
			}
		});
 
		// A listener on the array radios
		$('.array-flexible-row table.question tbody td').click(function(el){
			// A small delay to allow the radio to be checked
			setTimeout(function() {
				// If less than 2 column-1 radios checked disable "Next"
				if($('.col-1 input.radio:checked').length < 2) {
					$('#movenextbtn').attr('disabled', true);
				}
				// If more than 1 column-1 radios checked enable "Next"
				else {
					$('#movenextbtn').attr('disabled', false);
				}
			}, 500); 
		});
	});
 
</script>

Here's your survey back with the script in the source of question 1.

File Attachment:

File Name: limesurvey...4_TP.lss
File Size:25 KB

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:

Please Log in to join the conversation.

More
5 years 2 months ago #75671 by malberghini
malberghini replied the topic: Require multiple answers of a specific option in an array?
That worked! Thanks!

Please Log in to join the conversation.

More
5 years 2 months ago #75673 by Mazi
Mazi replied the topic: Require multiple answers of a specific option in an array?

malberghini wrote: That worked! Thanks!

You're welcome :-)

If our hints have been helpful and you enjoy limesurvey please consider a donation to the team .
We do all this in our free time and you don't have to pay a penny for this software.

Without your help we can't keep this project alive.


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now