Quantcast
Viewing all articles
Browse latest Browse all 17529

Unchecking excluded checkboxes - by: tpartner

Here is an updated version if the script that should handle both types of multiple-choice.

<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		// Identify this question
		var thisQuestion = $('#question{QID}');
 
		// Add some classes
		$('.question-item:not(:last)', thisQuestion).addClass('non-exclusive-item');
		$('.question-item:last', thisQuestion).addClass('exclusive-item');
 
		// Handle exclusive items
		$('input.checkbox', thisQuestion).on('change', function(e) {
			if($(this).is(':checked')) {
				var actionItems = $('.non-exclusive-item', thisQuestion);
				if($(this).closest('.question-item').hasClass('non-exclusive-item')) {
					actionItems = $('.exclusive-item', thisQuestion);
				}
				actionItems.each(function(i) {
					$('input.checkbox', this).prop('checked', false).trigger('change');
					$('input:hidden', this).attr('value', '');
					$('input[type="text"]', this).val('').trigger('keyup');
				});
			}
		});
 
	});
</script>

Viewing all articles
Browse latest Browse all 17529

Trending Articles