- Posts: 409
- Thank you received: 34
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Help restricting selectable multiple choice answers
- blocka
- Topic Author
- Offline
- Platinum Member
Less
More
6 years 5 months ago - 6 years 5 months ago #161218
by blocka
Help restricting selectable multiple choice answers was created by blocka
I have a multiple choice question where some answer options are mutually exclusive, and I'd like to impose logic to enforce this (ideally by hiding/showing allowed options in real-time).
Here's my question and the rules:
Please select from the items below:
1) Answer choice 1
2) Answer choice 2
3) Answer choice 3
4) Answer choice 4
5) None of the above
6) Don’t know
7) Not applicable
Rules:
A. If I select "1) answer choice 1" and/or "2) answer choice 2" and/or "3) answer choice 3" and/or "4) answer choice 4"
--> Then I would not be able to select "5) None of the above", "6) Don’t know", or "7) Not Applicable"
B. If I select "5) None of the above",
--> Then I would not be able to select 1) or 2) or 3) or 4) or 6) or 7)
C. If I select "6) Don’t know",
--> Then I would not be able to select 1) or 2) or 3) or 4) or 5) or 7)
D. If I select "7) Not applicable",
--> Then I would not be able to select 1) or 2) or 3) or 4) or 5) or 6)
Here's my question and the rules:
Please select from the items below:
1) Answer choice 1
2) Answer choice 2
3) Answer choice 3
4) Answer choice 4
5) None of the above
6) Don’t know
7) Not applicable
Rules:
A. If I select "1) answer choice 1" and/or "2) answer choice 2" and/or "3) answer choice 3" and/or "4) answer choice 4"
--> Then I would not be able to select "5) None of the above", "6) Don’t know", or "7) Not Applicable"
B. If I select "5) None of the above",
--> Then I would not be able to select 1) or 2) or 3) or 4) or 6) or 7)
C. If I select "6) Don’t know",
--> Then I would not be able to select 1) or 2) or 3) or 4) or 5) or 7)
D. If I select "7) Not applicable",
--> Then I would not be able to select 1) or 2) or 3) or 4) or 5) or 6)
Last edit: 6 years 5 months ago by blocka.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10115
- Thank you received: 3597
6 years 5 months ago #161225
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Help restricting selectable multiple choice answers
Please refer to the manual - Exclusive Options -
manual.limesurvey.org/Question_type_-_Mu...xclude_all_others.29
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- blocka
- Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 409
- Thank you received: 34
6 years 5 months ago #161229
by blocka
Replied by blocka on topic Help restricting selectable multiple choice answers
Attachments:
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10115
- Thank you received: 3597
6 years 5 months ago #161231
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Help restricting selectable multiple choice answers
To do that, you will need to use JavaScript instead of the built-in exclusive feature. Something like in
this post
but modified to render all options placed greater than 4 exclusive.
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Identify this question var thisQuestion = $('#question{QID}'); // Add some classes $('.question-item:not(:gt(3))', thisQuestion).addClass('non-exclusive-item'); $('.question-item:gt(3)', thisQuestion).addClass('exclusive-item'); // Handle exclusive items $('input.checkbox', thisQuestion).on('change', function(e) { if($(this).is(':checked')) { var actionItems = $('.question-item', thisQuestion).not($(this).closest('.question-item')); if($(this).closest('.question-item').hasClass('non-exclusive-item')) { actionItems = $('.exclusive-item', thisQuestion); } actionItems.each(function(i) { $('input.checkbox', this).prop('checked', false).trigger('change'); $('input:hidden', this).attr('value', ''); $('input[type="text"]', this).val('').trigger('keyup'); }); } }); }); </script>
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.