Multiple choice and block selecting more then max

More
3 years 10 months ago #115576 by cmd
cmd created the topic: Multiple choice and block selecting more then max
Hi,
I want to ask about multiple choice question. I set max quantity of answears on 3, how to deny users to check more then 3 answears in real time. If 3 answears are checked then user can't check any other.

Please help and sorry for my English.

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

More
3 years 10 months ago #115582 by jelo
jelo replied the topic: Multiple choice and block selecting more then max
Did you already checked the advanced settings of the question?

There you'll find:
Minimum answers
Maximum answers

This might help.

Are you a student conducting a survey? If yes, tell me why you use LimeSurvey?
www.limesurvey.org/forum/development/116...y-you-use-limesurvey

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

More
3 years 10 months ago - 3 years 10 months ago #115591 by tpartner
tpartner replied the topic: Multiple choice and block selecting more then max
Adding a script like this, for example, will disable all unchecked boxes if 3 are checked. Modify "maxAnswers" as required.

<script type="text/javascript" charset="utf-8">	
	$(document).ready(function() {
 
		// Maximun answers
		var maxAnswers = 3;
 
		// Identify this question
		var thisQuestion = $('#question{QID}');
 
		function checkMax() {
			$('input.checkbox', thisQuestion).prop('disabled', false);
			if($('input.checkbox:checked', thisQuestion).length >= maxAnswers) {
				$('input.checkbox', thisQuestion).not(':checked').prop('disabled', true);
			}
		}
 
		// Initial checkbox states
		checkMax();
 
		// Listener on the checkboxes
		$('input.checkbox', thisQuestion).change(function(e) {
			checkMax();
		});
 
		// Remove any "disabled" properties before submitting
		$('#movenextbtn, #movesubmitbtn').bind('click', function () {			
			$('input.checkbox', thisQuestion).prop('disabled', false);
		});
 
    });
</script>

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last Edit: 3 years 10 months ago by tpartner.

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

More
3 years 10 months ago #115640 by cmd
cmd replied the topic: Multiple choice and block selecting more then max
Thank you very much - works great!
Google told nothing so I just asked..

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

More
3 years 7 months ago #117426 by faktormarc
faktormarc replied the topic: Multiple choice and block selecting more then max
Hey,

this solutions sounds perfect, but didnt work on my installation.

Where should i place the script? (Version 2.05+ Build 140612)

thx for your advice!

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

More
3 years 7 months ago #117436 by tpartner
tpartner replied the topic: Multiple choice and block selecting more then max
Place the script in the source of the question - manual.limesurvey.org/Workarounds:_Manip....29_in_LimeSurvey.3F

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
3 years 7 months ago #117438 by jelo
jelo replied the topic: Multiple choice and block selecting more then max
Since you are in the LS-Team, I wonder if implementing your workaround into the Limesurvey core are a discussion topic. For example this script here could be an additional option in the question.

What are the pro / contra for adding some of your "workarounds" to the codebase?

BTW: Your avatar cannot be true. How can you type with your hands behind your head? You are providing help here all the time.

Are you a student conducting a survey? If yes, tell me why you use LimeSurvey?
www.limesurvey.org/forum/development/116...y-you-use-limesurvey

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

More
3 years 7 months ago #117446 by faktormarc
faktormarc replied the topic: Multiple choice and block selecting more then max
thank you, this solution works fine.

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

More
3 years 7 months ago #117453 by holch
holch replied the topic: Multiple choice and block selecting more then max
Toes, Tony, writes with his toes when the hands are occupied... ;-)

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

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

More
3 years 7 months ago #117456 by Ben_V
Ben_V replied the topic: Multiple choice and block selecting more then max

Jelo wrote: How can you type with your hands behind your head?


You have to accept that Tony perfectly knows how to take advantage of some new and efficient wearable devices like those new but not publicy released google sunglasses. The red cap probably provides an incredible cooling solution normally used for data centers. Only the use of those 2 not referenced smartwatches remains unclear… :laugh:

Benoît

EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)

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

More
3 years 7 months ago #117492 by tpartner
tpartner replied the topic: Multiple choice and block selecting more then max
@holch, @Ben_V: Yeah, yeah, funny guys :laugh: . Ben got most of the equipment right but don't overthink the watches - one, well, tells me the time, the other is actually a wristband for unlimited food and beer ;) .

@jelo, Please add the workaround to Feature Requests if you feel it's warranted.


.

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
6 months 2 weeks ago #166549 by stephanied
stephanied replied the topic: Multiple choice and block selecting more then max
This code works great in version 2.73.1. I would like to take it one step further and partially randomize and fix one answer to the bottom of the list. For multiple choice questions I typically use the following function:
<script type="text/javascript" charset="utf-8">	
	$(document).ready(function() {
		keepPos('{SGQ}',['SQ004|4']) //	keepPos('{SGQ}',['code|position'])
	});
</script>
Thanks in advance!

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

More
1 month 2 weeks ago - 1 month 2 weeks ago #173274 by JeeWee
JeeWee replied the topic: Multiple choice and block selecting more then max
Hi,

I was wondering if someone knows an update for the code in Limesurvey 3. I can't seem to get it to work.

I figured the following part doesn't work:
$('input.checkbox', thisQuestion).change(function(e) {
			checkMax();
		});

To test, I've added an alert:
$('input.checkbox', thisQuestion).change(function(e) {
alert('hello');
			checkMax();
		});
Whenever i enable or disable a checkbox there's no alert.
TO make sure javascript works i added the alert at the beginning, and that shows me an alert when the page loads:
<script type="text/javascript" charset="utf-8">	
	$(document).ready(function() {
 alert('hello');
		// Maximun answers
		var maxAnswers = 3;
 
		// Identify this question
		var thisQuestion = $('#question{QID}');
 
		function checkMax() {
			$('input.checkbox', thisQuestion).prop('disabled', false);
			if($('input.checkbox:checked', thisQuestion).length >= maxAnswers) {
				$('input.checkbox', thisQuestion).not(':checked').prop('disabled', true);
			}
		}
 
		// Initial checkbox states
		checkMax();
 
		// Listener on the checkboxes
		$('input.checkbox', thisQuestion).change(function(e) {
			checkMax();
		});
 
		// Remove any "disabled" properties before submitting
		$('#movenextbtn, #movesubmitbtn').bind('click', function () {			
			$('input.checkbox', thisQuestion).prop('disabled', false);
		});
 
    });
</script>
Last Edit: 1 month 2 weeks ago by JeeWee.

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

More
1 month 2 weeks ago #173277 by jelo
jelo replied the topic: Multiple choice and block selecting more then max
In LS3 the old workarounds no longer work.

E.g.the format of 'input.checkbox' is now 'input [type="checkbox"]'.
Take a look at some other threads, where old scripts were rewritten.
Perhaps you can get your script fixed with these example.

www.limesurvey.org/forum/can-i-do-this-w...oxes?start=15#168095

Are you a student conducting a survey? If yes, tell me why you use LimeSurvey?
www.limesurvey.org/forum/development/116...y-you-use-limesurvey

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

More
1 month 2 weeks ago #173286 by JeeWee
JeeWee replied the topic: Multiple choice and block selecting more then max
Thanks for the tip. I managed to get it to work, also with thanks to the jquery documentation. I changed the function checkmax:
function checkMax() {
			$('input[type="checkbox"]', thisQuestion).prop('disabled', false);
			if($("input:checked", thisQuestion).length >= maxAnswers) {
				$('input[type="checkbox"]', thisQuestion).not(':checked').prop('disabled', true);
			}
		}

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!