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

TOPIC: Multiple types in array - rank all then choose some items

Multiple types in array - rank all then choose some items 3 months 2 weeks ago #110594

  • tpartner
  • tpartner's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 4257
  • Thank you received: 801
  • Karma: 367
Hi Elisa,

Try this:

<script type="text/javascript" charset="utf-8">	
 
	$(document).ready(function(){
 
		// The error messages
		var error1 = 'You can only select 5 attributes.';
		var error2 = 'Please select 5 attributes.';
 
		// Identify the questions
		var thisQuestion = $('#question{QID}');
		var nextMultiOpt = $(thisQuestion).nextAll('.multiple-opt:eq(0)');
 
		// Add a class to the array question (for styling) 
		$(thisQuestion).addClass('array-plus-checkboxes');
 
		// Hide the next question 
		$(nextMultiOpt).hide();
 
		// Add an extra column to the array
		$('table.question thead tr', thisQuestion).append('<th class="newColumn1" />');
		$('table.question tbody tr', thisQuestion).each(function(i) {
			$(this).append('<td class="newColumn1" />');
		});
 
		// Move the hidden question text to the inserted column
		$('table.question thead tr th.newColumn1', thisQuestion).text($('.questiontext', nextMultiOpt).text());
 
		// Move the checkboxes into the array
		$('input.checkbox', nextMultiOpt).each(function(i){
			$('table.question tbody tr:eq('+i+') td.newColumn1', thisQuestion).append(this);
		});
 
		// Listener on the checkboxes (to test for maximum 5 checked boxes)
		$('input.checkbox', thisQuestion).click(function(event) {
			if($('input.checkbox:checked', thisQuestion).length > 5) {
				alert(error1);
				$(this).attr('checked', false);
			}
			if($('input.checkbox:checked', thisQuestion).length == 5) {
				$('th.newColumn1', thisQuestion).removeClass('mandatory-error');
			}
		});
 
		// Interrupt the Next/Submit function (to test for minimum 5 checked boxes)
		$('#movenextbtn, #movesubmitbtn').bind('click', function () {
 
			$('th.newColumn1', thisQuestion).removeClass('mandatory-error');
 
			if($('input.checkbox:checked', thisQuestion).length < 5) {
				$('th.newColumn1', thisQuestion).addClass('mandatory-error');
				alert(error2);
				return false;
			}
		});
 
		// Some cleanup styles
		$('col', thisQuestion).css({
			'width': 'auto'
		});
 
	});
</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.
The following user(s) said Thank You: elisa

Multiple types in array - rank all then choose some items 3 months 1 week ago #110690

  • elisa
  • elisa's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 11
  • Thank you received: 2
  • Karma: 0
Thanks a lot Tony. It works perfecty.
Cheers,
Elisa
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.111 seconds
Donation Image