Welcome to the LimeSurvey Community Forum

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

Send error message if user selects more than 2 times "yes" on one page

  • dvenohr
  • dvenohr's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 8 months ago - 6 years 8 months ago #156351 by dvenohr
Hi everyone,

I'd like to use limesurvey as a tool for respondents selecting optional items from an item list. I managed to build a survey in which there are 3 items, all of them are selectable through a "yes/no" question type. I'd like limesurvey to only allow the user to select as many as 2 items from 3 (Later there he's allowed to select maybe 25 items from a list of 40 items or so).
What would also be needed in addition is that the maximum of selectable items is defined through a token value, so that the definition of the max-value will be through a value stored in the token table. The purpose of that is that one can assign each potential user a unique max-value.

How could that be achieved? (if it is possible at all?)

One remark: I know an easier way would perhaps be a multiple choice question, however, the task is a bit more complicated. once the user selects one item by clicking "yes", a dropdown-field appears in which he or she can select the exact wording of that item. for achieving an appropriate layout, I used a javascript code which I found in some of the workarounds sections of limesurvey (or in an example lss file, I can't remember exactly).

At the moment the layout of the questions looks like attached...


thanks in advance,
Daniel
(LimeSurvey 2.6.2)
Last edit: 6 years 8 months ago by dvenohr.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 8 months ago - 6 years 8 months ago #156356 by tpartner
As we have no clue what code you used to achieve that layout and functionality, it's hard to give constructive advice.

Having said that, I imagine you will need to put a listener on the radios and disable the unchecked ones when a maximum is reached. Something like this (untested):

Code:
<script type="text/javascript" charset="utf-8">
  $(document).ready(function(){  
 
    var maxAllowed = {TOKEN:ATTRIBUTE_1};
 
    // Listener on the radios
    $('.yes-no input[type="radio"]').on('click', function(e) {
      // Reset the radios
      $('.yes-no input[type="radio"][value="Y"]').prop('disabled', false);
 
      // Test for max allowed 
      if($('.yes-no input[type="radio"][value="Y"]:checked').length == maxAllowed) {
        // If true, disable all unchecked "Yes" radios
        $('.yes-no input[type="radio"][value="Y"]:not(:checked)').prop('disabled', true);
      }
    });
  });
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 6 years 8 months ago by tpartner.
The topic has been locked.
  • dvenohr
  • dvenohr's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 8 months ago #156365 by dvenohr
Hi, looks good, I will test it and write about the success. If it fails I will send my code in the next reply.
thank you very much for your answer!
The topic has been locked.
  • dvenohr
  • dvenohr's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 8 months ago #156373 by dvenohr
Hello again, I tested your code and it works perfect - wow! Thank you so much!
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose