Unchecking excluded checkboxes

Mehr
2 Jahre 4 Monate her #146681 von tpartner
COM_KUNENA_MESSAGE_REPLIED_NEW
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>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
Folgende Benutzer bedankten sich: andre_twang, Trmiey_124040

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
2 Jahre 4 Monate her #146705 von andre_twang
COM_KUNENA_MESSAGE_REPLIED_NEW
Thanks Tony! It worked really well!

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
1 Jahr 1 Monat her #167341 von tixeon
COM_KUNENA_MESSAGE_REPLIED_NEW
I have tried using this script in version 2.6.7-lts Build 171212 and it doesn’t work. Is there an updated code that will?

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
1 Jahr 1 Monat her #167343 von Joffm
COM_KUNENA_MESSAGE_REPLIED_NEW
Hi, tixeon,

In the first post of this thread you see that it is about the 2.50-2.73 branch.

You work with the older 2.06 branch, which was renamed - to confuse some users - to 2.6.x

So you cannot expect the script to work.

Best regards
Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
1 Jahr 1 Monat her #167427 von tpartner
COM_KUNENA_MESSAGE_REPLIED_NEW

I have tried using this script in version 2.6.7-lts Build 171212 and it doesn’t work.

I just tested and it does work in 2.06 LTS. Can you attach a small sample survey containing only the affected question?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
1 Jahr 3 Wochen her #167924 von krosser
COM_KUNENA_MESSAGE_REPLIED_NEW

tpartner schrieb: Try this:

<script type="text/javascript" charset="utf-8">		
 
	$(document).ready(function() {
 
		// Identify this question
		var thisQuestion = $('#question{QID}');
 
		// Uncheck all excluded items
		$('div.question-item:last input.checkbox', thisQuestion).on('change', function(e) {
			if($(this).is(':checked')) {
				$('input.checkbox', thisQuestion).not($(this)).each(function(i) {
					$(this).prop('checked', false);
					$(this).nextAll('input:hidden:eq(0)').attr('value', '');
				});
				$('input[type="text"]', thisQuestion).val('');
			}
		});
 
	});
</script>


Just tested these workarounds and, unfortunately, they do not work anymore in LS 3.7. :(

I'm using the latest LS 3.17 hosted on LS servers, not installed locally.
Anhang:

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
1 Jahr 3 Wochen her - 1 Jahr 3 Wochen her #167932 von tpartner
COM_KUNENA_MESSAGE_REPLIED_NEW
Try changing all instances of 'input.checkbox' to 'input [type="checkbox"]'

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
Last edit: 1 Jahr 3 Wochen her by tpartner.

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
1 Jahr 3 Wochen her #167950 von krosser
COM_KUNENA_MESSAGE_REPLIED_NEW

tpartner schrieb: Try changing all instances of 'input.checkbox' to 'input [type="checkbox"]'


Tried to change it in both lines where it is, but it didn't solve it.

I'm using the latest LS 3.17 hosted on LS servers, not installed locally.

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
1 Jahr 3 Wochen her #167964 von tpartner
COM_KUNENA_MESSAGE_REPLIED_NEW
Sorry, I am away this week with only a phone so can't debug any further.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
1 Jahr 2 Wochen her #168095 von tpartner
COM_KUNENA_MESSAGE_REPLIED_NEW
This will work in 3.x:

<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[type="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[type="checkbox"]', this).prop('checked', false).trigger('change');
					$('input:hidden', this).attr('value', '');
					$('input[type="text"]', this).val('').trigger('keyup');
				});
			}
		});
		$('input[type="text"]', thisQuestion).on('keyup change', function(e) {
			var thisInput = $(this);
			setTimeout(function() {
				$(thisInput).closest('.question-item').find('input[type="checkbox"]').trigger('change');
			}, 200);
		});
 
	});
</script>

Sample survey attached:

Dateianhang:

Dateiname: limesurvey...2965.lss
Dateigröße:16 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
Anhang:

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
10 Monate 4 Tage her #171282 von Andrea01
COM_KUNENA_MESSAGE_REPLIED_NEW
Hi Tony,

for your script:

<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>

Is there a way to handle two exclusive options???

Thanks and best regards
Andrea

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
10 Monate 3 Tage her #171315 von tpartner
COM_KUNENA_MESSAGE_REPLIED_NEW
This script will render the last two items exclusive:

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

Sample survey attached:

Dateianhang:

Dateiname: limesurvey...9651.lss
Dateigröße:17 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
Anhang:

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
10 Monate 3 Tage her #171340 von Andrea01
COM_KUNENA_MESSAGE_REPLIED_NEW
Thank you Tony, perfect as always.

Andrea

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
4 Monate 4 Wochen her #178675 von rizkiheryandi
COM_KUNENA_MESSAGE_REPLIED_NEW

tpartner schrieb: This will work in 3.x:

<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[type="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[type="checkbox"]', this).prop('checked', false).trigger('change');
					$('input:hidden', this).attr('value', '');
					$('input[type="text"]', this).val('').trigger('keyup');
				});
			}
		});
		$('input[type="text"]', thisQuestion).on('keyup change', function(e) {
			var thisInput = $(this);
			setTimeout(function() {
				$(thisInput).closest('.question-item').find('input[type="checkbox"]').trigger('change');
			}, 200);
		});
 
	});
</script>

Sample survey attached:

Dateianhang:

Dateiname: limesurvey...2965.lss
Dateigröße:16 KB


Thanks it's works for latest Limesurvey

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Jetzt loslegen!

Melden Sie sich jetzt an, und erstellen Sie in wenigen Minuten Ihre erste Umfrage.

Account einrichten

Abonnieren Sie unseren Newsletter

Abonnieren Sie unseren Newsletter für alle Neuigkeiten rund um LimeSurvey
captcha