Quantcast
Viewing all articles
Browse latest Browse all 17529

Last Option In Array (Numbers) (Checkboxes) Row Excludes All Others - by: tpartner

Try this. Note that if using 1.92+, you do not need to replace "{QID}" - this tag will automatically insert the question ID:

<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) {
			$('.normalOpt:last', this).removeClass('normalOpt').addClass('exlusiveOpt')
		});
 
		// A listener on the checkbox cells
		$('table.question tbody td', thisQuestion).click(function (event) {
 
			// Set some vars
			var thisRow = $(this).closest('tr');
 
			// Uncheck the appropriate boxes in a row
			if ($(this).hasClass('normalOpt')) {
				$('.exlusiveOpt input[type=checkbox]', thisRow).attr('checked', false);
			}
			else {
				$('.normalOpt input[type=checkbox]', thisRow).attr('checked', false);
			}
		});
 
		// A listener on the checkboxes
		$('table.question tbody td input[type=checkbox]', thisQuestion).click(function (event) {
 
			// Set some vars
			var thisRow = $(this).closest('tr');
			var thisCell = $(this).closest('td');
 
			// Uncheck the appropriate boxes in a row
			if ($(thisCell).hasClass('normalOpt')) {
				$('.exlusiveOpt input[type=checkbox]', thisRow).attr('checked', false);
			}
			else {
				$('.normalOpt input[type=checkbox]', thisRow).attr('checked', false);
			}
		});
	}	
</script>


I have updated the workaround - manual.limesurvey.org/wiki/Workarounds:_..._Excludes_All_Others

Viewing all articles
Browse latest Browse all 17529

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>