Unchecking excluded checkboxes

More
2 years 1 month ago #141400 by BBCMResearch
BBCMResearch created the topic: Unchecking excluded checkboxes
Hello,

I have several multiple choice questions in a survey that use the exclusive option for a "none of the above" answer.

If someone clicks other answer options before clicking "none of the above," these other selected answers become grayed-out, which normally would be fine. However, I need them to become "un-checked" as well.

Based on the solution tpartner gave here , it appears that I can insert a script to uncheck other boxes if the exclusive option is selected.

However, I don't know enough to code it. I would greatly appreciate it if someone could help me out.

I use Version 2.50+160901

Thanks!

Please Log in or Create an account to join the conversation.

More
2 years 1 month ago #141447 by tpartner
tpartner replied the topic: Unchecking excluded checkboxes
Assuming the exclusive item is last, add this to the question source of the multiple choice questions:

<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', '');
				});
			}
		});
	});
</script>

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: BBCMResearch

Please Log in or Create an account to join the conversation.

More
2 years 1 month ago #141463 by BBCMResearch
BBCMResearch replied the topic: Unchecking excluded checkboxes
Excellent as always.

However, I do have one question where the last two items in the list are both exclusive. Could you adapt the script to work for both items?

Thanks!

Please Log in or Create an account to join the conversation.

More
2 years 1 month ago #141469 by tpartner
tpartner replied the topic: Unchecking excluded checkboxes
<script type="text/javascript" charset="utf-8">		
	$(document).ready(function(){
 
		// Identify this question
		var thisQuestion = $('#question{QID}');
 
		// Uncheck all excluded items
		var itemsLength = $('div.question-item', thisQuestion).length;
		$('div.question-item:gt('+(itemsLength-3)+') 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', '');
				});
			}
		});
	});
</script>

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: BBCMResearch

Please Log in or Create an account to join the conversation.

More
2 years 1 month ago #141471 by BBCMResearch
BBCMResearch replied the topic: Unchecking excluded checkboxes
Thanks!

Please Log in or Create an account to join the conversation.

More
1 year 9 months ago #146209 by BBCMResearch
BBCMResearch replied the topic: Unchecking excluded checkboxes
Tony,

Thanks for your previous help with this. I now need to use this same script, but with an Other option enabled. However, the Other option is not the exclusive one. So you can enter text into the other field, and that remains visible after the exclusive option is checked.

Is it possible to reset the text field for the other option when the exclusive option is checked?

Thanks!

Please Log in or Create an account to join the conversation.

More
1 year 9 months ago #146232 by DenisChenu
DenisChenu replied the topic: Unchecking excluded checkboxes

BBCMResearch wrote: .....
Is it possible to reset the text field for the other option when the exclusive option is checked?
....

Don't crosspost please ......
www.limesurvey.org/forum/can-i-do-this-w...lusive-option#146231

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .

Please Log in or Create an account to join the conversation.

More
1 year 9 months ago #146252 by tpartner
tpartner replied the topic: Unchecking excluded checkboxes
BBCMResearch, is the exclusive item last?

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in or Create an account to join the conversation.

More
1 year 9 months ago #146271 by BBCMResearch
BBCMResearch replied the topic: Unchecking excluded checkboxes
Hi Tony,

Yes, the exclusive item is last, and the other option is just before it.

Please Log in or Create an account to join the conversation.

More
1 year 9 months ago #146285 by tpartner
tpartner replied the topic: Unchecking excluded checkboxes
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>

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: BBCMResearch

Please Log in or Create an account to join the conversation.

More
1 year 9 months ago #146286 by BBCMResearch
BBCMResearch replied the topic: Unchecking excluded checkboxes
Works like a charm, thanks Tony!

Please Log in or Create an account to join the conversation.

More
1 year 9 months ago - 1 year 9 months ago #146292 by DenisChenu
DenisChenu replied the topic: Unchecking excluded checkboxes
Hi Tony,

Just something about javascripting answer and EM, think it's better to use
$(this).prop('checked', false).trigger('change');
$('input[type="text"]', thisQuestion).val('').triiger('keyup')

Unsure it work on 2.5X, but i hope it work directly in 3.0 : see github.com/LimeSurvey/LimeSurvey/blob/de...em_javascript.js#L22

If it don't work : it's a bug

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .
Last Edit: 1 year 9 months ago by DenisChenu.

Please Log in or Create an account to join the conversation.

More
1 year 9 months ago #146301 by tpartner
tpartner replied the topic: Unchecking excluded checkboxes
Hmm...I just tested in 2.5.7 and don't seem to need those trigger events to fire Expression Manager

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in or Create an account to join the conversation.

More
1 year 9 months ago #146306 by DenisChenu
DenisChenu replied the topic: Unchecking excluded checkboxes

tpartner wrote: Hmm...I just tested in 2.5.7 and don't seem to need those trigger events to fire Expression Manager

Yes, because it was inlined
<input type="radio" onclick="checkconditions($(this).val(), $(this).attr('name'), 'radio', 'click') />
And, sometimes this part was lost in HTML. Using a global event don't add an event to each input , and workaround can be more easy.

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .

Please Log in or Create an account to join the conversation.

More
1 year 9 months ago #146649 by andre_twang
andre_twang replied the topic: Unchecking excluded checkboxes
Hi Tony,

Your scripts have been extremely helpful! Could I ask what about unchecking excluded checkboxes for "Multiple Choice with Comments" question type, please? This script seems to work for "Multiple Choices" but not for the "Multiple Choices with Comments"

Warm regards,

Andre

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!