- Posts: 3
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Max answers from Multiple Choice
- wut
- Topic Author
- Offline
- New Member
Less
More
9 years 1 month ago #118270
by wut
Max answers from Multiple Choice was created by wut
Hi
I am having a few issues with the max answers for multiple choice. Am I able to have 3 multiple choice questions in a question group, and then have a max of X answers from the 3 total questions?
Below is an example:
Question Group 1 (only select a max of 2 from the 3 questions below)
Question 1
SubQuestion1 []
SubQuestion2 []
Question 2
SubQuestion1 []
SubQuestion2 []
Question 3
SubQuestion1 []
SubQuestion2 []
Thanks!
I am having a few issues with the max answers for multiple choice. Am I able to have 3 multiple choice questions in a question group, and then have a max of X answers from the 3 total questions?
Below is an example:
Question Group 1 (only select a max of 2 from the 3 questions below)
Question 1
SubQuestion1 []
SubQuestion2 []
Question 2
SubQuestion1 []
SubQuestion2 []
Question 3
SubQuestion1 []
SubQuestion2 []
Thanks!
The topic has been locked.
- holch
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 11655
- Thank you received: 2742
9 years 1 month ago #118274
by holch
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Replied by holch on topic Max answers from Multiple Choice
I don't think this is possible. If they are all on the same page, you might be able to check something via Javascript, but the maximum answer option is only for one question.
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.
- wut
- Topic Author
- Offline
- New Member
Less
More
- Posts: 3
- Thank you received: 0
9 years 1 month ago #118276
by wut
Replied by wut on topic Max answers from Multiple Choice
So Javascript is the only way?
I am trying to have an array from Question Group 1 with i) Important ii) Kind of important iii) Not Important as answers for statements. Then based on what they have answered from Question Group 1, Question Group 2 will show what statements were marked as Important, Kind of, Not, each in it's own question. Then you'll be able to select a max of 3 statements from the entire Question Group 2.
Sorry if that was difficult to follow.
I am trying to have an array from Question Group 1 with i) Important ii) Kind of important iii) Not Important as answers for statements. Then based on what they have answered from Question Group 1, Question Group 2 will show what statements were marked as Important, Kind of, Not, each in it's own question. Then you'll be able to select a max of 3 statements from the entire Question Group 2.
Sorry if that was difficult to follow.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10108
- Thank you received: 3593
9 years 1 month ago - 9 years 1 month ago #118281
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 Max answers from Multiple Choice
Assuming the only multiple-choice questions in group 2 are those you want to count from,
set up your survey to use JavaScript
and place the following script in the source of one of the questions:
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Interrupt the Next/Submit function $('#movenextbtn, #movesubmitbtn').click(function(e){ if($('.multiple-opt:visible input.checkbox:checked').length > 2) { alert('You can only select up to 2 items.'); return 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 1 month ago by tpartner.
The following user(s) said Thank You: Ben_V
The topic has been locked.
- wut
- Topic Author
- Offline
- New Member
Less
More
- Posts: 3
- Thank you received: 0
9 years 1 month ago #118282
by wut
Replied by wut on topic Max answers from Multiple Choice
Awesome! This is exactly what I was looking for.
Thanks a lot!
Thanks a lot!
The topic has been locked.
- Bigred01
- Offline
- Premium Member
Less
More
- Posts: 88
- Thank you received: 33
9 years 1 month ago #118287
by Bigred01
Replied by Bigred01 on topic Max answers from Multiple Choice
You could also use javascript to insert question text/headers into a single questions answer list to give it the appearance of being multiple questions but you could use the max answers option in the advanced setting to limit how many they can select. Jquerys insertBefore for example.
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13642
- Thank you received: 2491
9 years 1 month ago #118297
by DenisChenu
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Replied by DenisChenu on topic Max answers from Multiple Choice
This don't work with EM ? Whole question validation (for each or only one (the first for example).
count(self,that.question2,that.question3) < 3
Give it a try
count(self,that.question2,that.question3) < 3
Give it a try
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
- Bigred01
- Offline
- Premium Member
Less
More
- Posts: 88
- Thank you received: 33
9 years 1 month ago #118302
by Bigred01
Replied by Bigred01 on topic Max answers from Multiple Choice
I want to add a quick note.
If you do go with the javascript logic, unless you are using a template that replaces alerts (like a bootstrap one) you may want to find a different way to display the error message.
If someone triggers the alert more than once, on most browsers they will get the option to suppress the alerts for that page. If they do this, their browser will stop the alert from popping up and break your mandatory logic at the same time allowing them to move to the next question without answering properly.
To avoid this you can add a blank div or span somewhere in the template and instead of using the alert, use jquery .text("Please select at most three options..") to display the error when it doesn't pass and .text("") to clear it when it does. This way they won't get the chance to supress an alert and break your script.
It sucks when it comes time to look at your data and a few people found a way to break your logic.
If you do go with the javascript logic, unless you are using a template that replaces alerts (like a bootstrap one) you may want to find a different way to display the error message.
If someone triggers the alert more than once, on most browsers they will get the option to suppress the alerts for that page. If they do this, their browser will stop the alert from popping up and break your mandatory logic at the same time allowing them to move to the next question without answering properly.
To avoid this you can add a blank div or span somewhere in the template and instead of using the alert, use jquery .text("Please select at most three options..") to display the error when it doesn't pass and .text("") to clear it when it does. This way they won't get the chance to supress an alert and break your script.
It sucks when it comes time to look at your data and a few people found a way to break your logic.
The following user(s) said Thank You: tpartner
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10108
- Thank you received: 3593
9 years 1 month ago #118308
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 Max answers from Multiple Choice
You try it Denis - it's buggy as hell!This don't work with EM ? Whole question validation (for each or only one (the first for example).
count(self,that.question2,that.question3) < 3
Give it a try
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10108
- Thank you received: 3593
9 years 1 month ago #118309
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 Max answers from Multiple Choice
Yes, good point.To avoid this you can add a blank div or span somewhere in the template
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- medveyt
- Offline
- New Member
Less
More
- Posts: 4
- Thank you received: 0
6 years 1 week ago - 6 years 1 week ago #167387
by medveyt
Replied by medveyt on topic Max answers from Multiple Choice
Hi!
I got a similar problem, but with more than one multiple choice questions, one with max 3 answers, other with max 2 answers, etc.
How can you modify the code to check for one specific question in the survey? I got stuck with it.
Thanks in advance!
I got a similar problem, but with more than one multiple choice questions, one with max 3 answers, other with max 2 answers, etc.
How can you modify the code to check for one specific question in the survey? I got stuck with it.
Thanks in advance!
Last edit: 6 years 1 week ago by medveyt.
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12921
- Thank you received: 3976
6 years 1 week ago #167396
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Max answers from Multiple Choice
Hi,
please do not answer to such an old thread.
What LS version? And is your problem really similar to the first post in this thread?
Here is a different approach:
Multiple question with headers.
and selecting more than 2 -> error
Works in 2.50-2.73 and 3.6x
The script to remove the checkboxes from the "header" options.
You see the "0", "4", "7" which refer to the position of the "header" subquestion , starting with "0"
some css to indent the options
I styled the headers in the subquestions like this (but up to you)
Regards
Joffm
please do not answer to such an old thread.
What LS version? And is your problem really similar to the first post in this thread?
Here is a different approach:
Multiple question with headers.
and selecting more than 2 -> error
Works in 2.50-2.73 and 3.6x
The script to remove the checkboxes from the "header" options.
You see the "0", "4", "7" which refer to the position of the "header" subquestion , starting with "0"
Code:
<script charset="utf-8" type="text/javascript"> $(document).ready(function() { $( '#question{QID} .question-item:eq(0)').addClass('hide-pseudo-elements').find('input.checkbox').remove(); $( '#question{QID} .question-item:eq(4)').addClass('hide-pseudo-elements').find('input.checkbox').remove(); $( '#question{QID} .question-item:eq(7)').addClass('hide-pseudo-elements').find('input.checkbox').remove(); }); </script>
some css to indent the options
Code:
<style type="text/css">.hide-pseudo-elements label::before, .hide-pseudo-elements label::after { display: none; } .hide-pseudo-elements .label-text { margin-left: -20px; } </style>
I styled the headers in the subquestions like this (but up to you)
Code:
<span style="font-size:12pt;background-color:#CCC;font-weight:bold;border: 1px solid #888;padding:2px">Part 1</span>
Regards
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:
The topic has been locked.