Welcome, Guest
Username: Password:
  • Page:
  • 1
  • 2

TOPIC: Require multiple answers of a specific option in an array?

Require multiple answers of a specific option in an array? 4 years 2 months ago #75556

Here it is.
Attachments:
The administrator has disabled public write access.

Require multiple answers of a specific option in an array? 4 years 2 months ago #75559

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5771
  • Thank you received: 1255
  • Karma: 514
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.
The administrator has disabled public write access.

Require multiple answers of a specific option in an array? 4 years 2 months ago #75671

That worked! Thanks!
The administrator has disabled public write access.

Require multiple answers of a specific option in an array? 4 years 2 months ago #75673

  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5919
  • Thank you received: 357
  • Karma: 258
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)limesurvey.org'"
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.163 seconds