Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Multiple choice and block selecting more then max

More
9 years 3 months ago #115576 by cmd
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.
The topic has been locked.
More
9 years 3 months ago #115582 by jelo
Did you already checked the advanced settings of the question?

There you'll find:
Minimum answers
Maximum answers

This might help.

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 3 months ago - 9 years 3 months ago #115591 by tpartner
Adding a script like this, for example, will disable all unchecked boxes if 3 are checked. Modify "maxAnswers" as required.

Code:
<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: 9 years 3 months ago by tpartner.
The topic has been locked.
More
9 years 3 months ago #115640 by cmd
Thank you very much - works great!
Google told nothing so I just asked..
The topic has been locked.
More
9 years 4 weeks ago #117426 by faktormarc
Replied by faktormarc on 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!
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 4 weeks ago #117436 by tpartner
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.
The topic has been locked.
More
9 years 4 weeks ago #117438 by jelo
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.

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The topic has been locked.
More
9 years 4 weeks ago #117446 by faktormarc
Replied by faktormarc on topic Multiple choice and block selecting more then max
thank you, this solution works fine.
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 4 weeks ago #117453 by holch
Toes, Tony, writes with his toes when the hands are occupied... ;-)

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
More
9 years 4 weeks ago #117456 by Ben_V

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)
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 3 weeks ago #117492 by tpartner
@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.
The topic has been locked.
More
5 years 11 months ago #166549 by stephanied
Replied by stephanied on 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:
Code:
<script type="text/javascript" charset="utf-8">  
  $(document).ready(function() {
    keepPos('{SGQ}',['SQ004|4']) //  keepPos('{SGQ}',['code|position'])
  });
</script>
Thanks in advance!
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose