Multiple choice - check all options

More
5 years 4 months ago #80943 by jporter
jporter created the topic: Multiple choice - check all options
I've looked around in the forums and haven't had much luck finding what I want to do.

The exclusive option doesn't work as I need because when you select it, it sets a value in the database for the exclusive option answer, not the other answers.

What I need is when I check the "All of the above" option, that it will place a check in all of the other answer options for a particular multiple choice question.

Please Log in to join the conversation.

More
5 years 4 months ago #80953 by DenisChenu
DenisChenu replied the topic: Multiple choice - check all options
Hello,

Maybe you can try at feature request :)

Denis

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 to join the conversation.

More
5 years 4 months ago #81896 by jporter
jporter replied the topic: Multiple choice - check all options
I have posted it there as well but I'm wondering if I could somehow create some javascript that might produce the results needed.

Please Log in to join the conversation.

More
5 years 4 months ago #81993 by Mazi
Mazi replied the topic: Multiple choice - check all options
Have a look at manual -> workarounds ->JavaScript, there are several examples which might be a good start.


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

More
5 years 4 months ago #82079 by tpartner
tpartner replied the topic: Multiple choice - check all options
Try this as a workaround.

1) Set up your survey to use JavaScript .

2) Add the following script to the source of the question. Replace "QQ" with the question ID .

The script puts a listener on the last checkbox of a question. If the box is checked, all other boxes in that question are checked and disabled.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function(){
 
		selectAll(QQ);
 
		function selectAll(qID) {
			// Initial setting
			if($('div#question'+qID+' input[id^="answer"]:last').attr('checked') == true) {
					$('div#question'+qID+' input[id^="answer"]').attr('checked', true).attr('disabled', true);
					$('div#question'+qID+' input[id^="answer"]:last').attr('disabled', false);
			}
 
			// Listener on last checkbox
			$('div#question'+qID+' input[id^="answer"]:last').click(function(){
				if($(this).attr('checked') == true) {
					$('div#question'+qID+' input[id^="answer"]').attr('checked', true).attr('disabled', true);
					$(this).attr('checked', true).attr('disabled', false);
				}
				else {
					$('div#question'+qID+' input[id^="answer"]').attr('checked', false).attr('disabled', false);
				}
			});
 
			// Re-enable checkboxes so data gets stored
			$('#moveprevbtn, #movenextbtn, #movesubmitbtn').click(function(){
				$('div#question'+qID+' input[id^="answer"]').attr('disabled', false);
			});
		}
	});
 
</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: jporter, Gibouille

Please Log in to join the conversation.

More
5 years 2 months ago #84624 by jporter
jporter replied the topic: Multiple choice - check all options
tpartner, thank you very much, that did exactly what I was trying to accomplish!

Please Log in to join the conversation.

More
1 month 1 week ago - 1 month 1 week ago #158316 by blocka
blocka replied the topic: Multiple choice - check all options
Many years since this was posted, but I'm a similar situation -- wanting to have the last option be "All of the above" and when clicked, have LS select all the other answer options in the question.

I tried the above in 2.67.3, build 170728 -- but it doesn't work any more...

Can someone suggestion an updated JS script -- I have to have each option selected so it is recorded in the response table, so the "Auto-check exclusive option if all others are checked" doesn't work for my use case.
Last Edit: 1 month 1 week ago by blocka.

Please Log in to join the conversation.

More
1 month 1 week ago #158350 by tpartner
tpartner replied the topic: Multiple choice - check all options
In version 2.67.x, this script will render the last checkbox as a "Select all" item.

<script type="text/javascript" charset="utf-8">
	$(document).on('ready pjax:complete',function() {
 
		// Identify this question
		var thisQuestion = $('#question{QID}');
 
		// Initial states
		if($('input[type="checkbox"]:last', thisQuestion).is(':checked')) {
			$('input[type="checkbox"]', thisQuestion).not(':last').prop('checked', true).prop('disabled', true);
		}
 
		// Listener on the last checkbox
		$('input[type="checkbox"]:last', thisQuestion).on('change', function(e) {
			if($(this).is(':checked')) {
				$('input[type="checkbox"]', thisQuestion).not(this).prop('checked', true).prop('disabled', true);
			}
			else {
				$('input[type="checkbox"]', thisQuestion).not(this).prop('disabled', false);
			}
 
			// Fire Expression Manager
			$('input[type="checkbox"]', thisQuestion).not(this).each(function(i) {
				checkconditions(this.value, this.name, this.type);
			});
		});
 
		// Re-enable checkboxes so data gets stored
		$('#moveprevbtn, #movenextbtn, #movesubmitbtn').on('click', function(){
			$('input[type="checkbox"]', thisQuestion).prop('disabled', false);
		});
	});
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...9-06.lss
File Size:18 KB

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

Please Log in to join the conversation.

More
1 month 1 week ago #158351 by tpartner
tpartner replied the topic: Multiple choice - check all options

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

Please Log in to join the conversation.

More
1 month 1 week ago - 1 month 1 week ago #158360 by blocka
blocka replied the topic: Multiple choice - check all options
That's awesome! Thank you!

Is there a way that if the last option is clicked again, all items would be unchecked (toggled)?

Also, in your example survey, you have :

-> Array filter exclusion: populated with "Q1"
-> Subquestion "Select All" : has a blank Relevance equation

Is there a reason for the above, or just artifacts that aren't required?
Last Edit: 1 month 1 week ago by blocka.

Please Log in to join the conversation.

More
1 month 1 week ago #158363 by tpartner
tpartner replied the topic: Multiple choice - check all options
1)
<script type="text/javascript" charset="utf-8">
	$(document).on('ready pjax:complete',function() {
 
		// Identify this question
		var thisQuestion = $('#question{QID}');
 
		// Initial states
		if($('input[type="checkbox"]:last', thisQuestion).is(':checked')) {
			$('input[type="checkbox"]', thisQuestion).not(':last').prop('checked', true).prop('disabled', true);
		}
 
		// Listener on the last checkbox
		$('input[type="checkbox"]:last', thisQuestion).on('change', function(e) {
			if($(this).is(':checked')) {
				$('input[type="checkbox"]', thisQuestion).not(this).prop('checked', true).prop('disabled', true);
			}
			else {
				$('input[type="checkbox"]', thisQuestion).not(this).prop('checked', false).prop('disabled', false);
			}
 
			// Fire Expression Manager
			$('input[type="checkbox"]', thisQuestion).not(this).each(function(i) {
				checkconditions(this.value, this.name, this.type);
			});
		});
 
		// Re-enable checkboxes so data gets stored
		$('#moveprevbtn, #movenextbtn, #movesubmitbtn').on('click', function(){
			$('input[type="checkbox"]', thisQuestion).prop('disabled', false);
		});
	});
</script>

2) Artifacts - ignore them.

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

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now