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

TOPIC: Last Option In Array (Numbers) (Checkboxes) Row Excludes All Others

Last Option In Array (Numbers) (Checkboxes) Row Excludes All Others 2 months 2 weeks ago #120483

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5029
  • Thank you received: 1038
  • Karma: 433
What version of LimeSurvey are you using? Please give a link to a small test survey.
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.

Last Option In Array (Numbers) (Checkboxes) Row Excludes All Others 2 months 2 weeks ago #120485

  • AndrejL
  • AndrejL's Avatar
  • Offline
  • Junior Lime
  • Posts: 39
  • Karma: 1
Of course.

We are using 2.00+,. And can not upgrade at this point.

I exported just this question here zadovoljstvo.sparslovenija.si/limesurvey...x.php/784886/lang-sl

First example uses first script and second one uses modified script.
Last Edit: 2 months 2 weeks ago by AndrejL.
The administrator has disabled public write access.

Last Option In Array (Numbers) (Checkboxes) Row Excludes All Others 2 months 2 weeks ago #120486

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5029
  • Thank you received: 1038
  • Karma: 433
2.00+ uses an old version of jQuery so you'll need to use this:

<script type="text/javascript" charset="utf-8">	
	$(document).ready(function() {
		// Call the exclude function using question ID
		excludeOpt ({QID});
	});
 
	// A function to make the last option in each array row exclusive
	function excludeOpt (qID) {
 
		var thisQuestion = $('#question'+qID)
 
		// Add some classes to the checkbox cells
		$('table.question tbody td', thisQuestion).addClass('normalOpt');
		$('table.question tbody tr', thisQuestion).each(function(i) {
			// Last two coluns are exclusive
			$('.normalOpt:last', this).removeClass('normalOpt').addClass('exlusiveOpt');
			$('.normalOpt:last', this).removeClass('normalOpt').addClass('exlusiveOpt');
		});
 
		// A listener on the checkboxes
		$('table.question tbody td input[type=checkbox]', thisQuestion).click(function (event) {
			handleCheckboxes($(this).closest('td'))
		});
 
		// A listener on the checkbox cells
		$('table.question td.question-item', thisQuestion).click(function (event) {
			handleCheckboxes($(this));
		});
 
		function handleCheckboxes(thisCell) {
			// Set some vars
			var thisRow = thisCell.closest('tr');
			var thisInput = $('input[type=checkbox]', thisCell);
 
			if(thisInput.is(':checked')) {
 
				// Uncheck the appropriate boxes in the row
				if ($(thisCell).hasClass('normalOpt')) { // Non-exclusive
					$('.exlusiveOpt input[type=checkbox]', thisRow).each(function(i) {
						$(this).attr('checked', false);
						$(this).closest('td').find('input[type="hidden"]').attr('value', '');
					});
				}
				else { // Exclusive
					$('input[type=checkbox]', thisRow).not(thisInput).each(function(i) {
						$(this).attr('checked', false);
						$(this).closest('td').find('input[type="hidden"]').attr('value', '');
					});
				}
			}
		}
	}
</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.

Last Option In Array (Numbers) (Checkboxes) Row Excludes All Others 2 months 2 weeks ago #120492

  • AndrejL
  • AndrejL's Avatar
  • Offline
  • Junior Lime
  • Posts: 39
  • Karma: 1
I works perfect!

Thank you Tony!
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.141 seconds