Willkommen, Gast
Benutzername: Passwort: Angemeldet bleiben:
  • Seite:
  • 1
  • 2

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

Last Option In Array (Numbers) (Checkboxes) Row Excludes All Others 1 Woche 3 Tage her #120483

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 4843
  • Dank erhalten: 987
  • Karma: 417
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.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Last Option In Array (Numbers) (Checkboxes) Row Excludes All Others 1 Woche 3 Tage her #120485

  • AndrejL
  • AndrejLs Avatar
  • OFFLINE
  • Junior Lime
  • Beiträge: 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.
Letzte Änderung: 1 Woche 3 Tage her von AndrejL.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Last Option In Array (Numbers) (Checkboxes) Row Excludes All Others 1 Woche 3 Tage her #120486

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 4843
  • Dank erhalten: 987
  • Karma: 417
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.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Last Option In Array (Numbers) (Checkboxes) Row Excludes All Others 1 Woche 3 Tage her #120492

  • AndrejL
  • AndrejLs Avatar
  • OFFLINE
  • Junior Lime
  • Beiträge: 39
  • Karma: 1
I works perfect!

Thank you Tony!
Der Administrator hat öffentliche Schreibrechte deaktiviert.
  • Seite:
  • 1
  • 2
Moderatoren: ITEd
Ladezeit der Seite: 0.129 Sekunden
Donation Image