- Posts: 3
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Multiple choice - check all options
- jporter
- Topic Author
- Offline
- New Member
Less
More
11 years 10 months ago #80943
by jporter
Multiple choice - check all options was created by jporter
I've looked around in the forums and haven't had much luck finding what I want to do.
The exclusive option doesn't work as I need because when you select it, it sets a value in the database for the exclusive option answer, not the other answers.
What I need is when I check the "All of the above" option, that it will place a check in all of the other answer options for a particular multiple choice question.
The exclusive option doesn't work as I need because when you select it, it sets a value in the database for the exclusive option answer, not the other answers.
What I need is when I check the "All of the above" option, that it will place a check in all of the other answer options for a particular multiple choice question.
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13624
- Thank you received: 2490
11 years 10 months ago #80953
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 Multiple choice - check all options
Hello,
Maybe you can try at feature request
Denis
Maybe you can try at feature request
Denis
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.
- jporter
- Topic Author
- Offline
- New Member
Less
More
- Posts: 3
- Thank you received: 0
11 years 10 months ago #81896
by jporter
Replied by jporter on topic Multiple choice - check all options
I have posted it there as well but I'm wondering if I could somehow create some javascript that might produce the results needed.
The topic has been locked.
- Mazi
- Offline
- Official LimeSurvey Partner
11 years 10 months ago #81993
by Mazi
Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
Replied by Mazi on topic Multiple choice - check all options
Have a look at manual -> workarounds -> JavaScript, there are several examples which might be a good start.
Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10103
- Thank you received: 3591
11 years 10 months ago #82079
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 Multiple choice - check all options
Try this as a workaround.
1) Set up your survey to use JavaScript .
2) Add the following script to the source of the question. Replace "QQ" with the question ID .
The script puts a listener on the last checkbox of a question. If the box is checked, all other boxes in that question are checked and disabled.
1) Set up your survey to use JavaScript .
2) Add the following script to the source of the question. Replace "QQ" with the question ID .
The script puts a listener on the last checkbox of a question. If the box is checked, all other boxes in that question are checked and disabled.
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ selectAll(QQ); function selectAll(qID) { // Initial setting if($('div#question'+qID+' input[id^="answer"]:last').attr('checked') == true) { $('div#question'+qID+' input[id^="answer"]').attr('checked', true).attr('disabled', true); $('div#question'+qID+' input[id^="answer"]:last').attr('disabled', false); } // Listener on last checkbox $('div#question'+qID+' input[id^="answer"]:last').click(function(){ if($(this).attr('checked') == true) { $('div#question'+qID+' input[id^="answer"]').attr('checked', true).attr('disabled', true); $(this).attr('checked', true).attr('disabled', false); } else { $('div#question'+qID+' input[id^="answer"]').attr('checked', false).attr('disabled', false); } }); // Re-enable checkboxes so data gets stored $('#moveprevbtn, #movenextbtn, #movesubmitbtn').click(function(){ $('div#question'+qID+' input[id^="answer"]').attr('disabled', false); }); } }); </script>
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: jporter, Gibouille
The topic has been locked.
- jporter
- Topic Author
- Offline
- New Member
Less
More
- Posts: 3
- Thank you received: 0
11 years 8 months ago #84624
by jporter
Replied by jporter on topic Multiple choice - check all options
tpartner, thank you very much, that did exactly what I was trying to accomplish!
The topic has been locked.
- blocka
- Offline
- Platinum Member
Less
More
- Posts: 409
- Thank you received: 34
6 years 7 months ago - 6 years 7 months ago #158316
by blocka
Replied by blocka on topic Multiple choice - check all options
Many years since this was posted, but I'm a similar situation -- wanting to have the last option be "All of the above" and when clicked, have LS select all the other answer options in the question.
I tried the above in 2.67.3, build 170728 -- but it doesn't work any more...
Can someone suggestion an updated JS script -- I have to have each option selected so it is recorded in the response table, so the "Auto-check exclusive option if all others are checked" doesn't work for my use case.
I tried the above in 2.67.3, build 170728 -- but it doesn't work any more...
Can someone suggestion an updated JS script -- I have to have each option selected so it is recorded in the response table, so the "Auto-check exclusive option if all others are checked" doesn't work for my use case.
Last edit: 6 years 7 months ago by blocka.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10103
- Thank you received: 3591
6 years 7 months ago #158350
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 Multiple choice - check all options
In version 2.67.x, this script will render the last checkbox as a "Select all" item.
Sample survey attached:
Code:
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:complete',function() { // Identify this question var thisQuestion = $('#question{QID}'); // Initial states if($('input[type="checkbox"]:last', thisQuestion).is(':checked')) { $('input[type="checkbox"]', thisQuestion).not(':last').prop('checked', true).prop('disabled', true); } // Listener on the last checkbox $('input[type="checkbox"]:last', thisQuestion).on('change', function(e) { if($(this).is(':checked')) { $('input[type="checkbox"]', thisQuestion).not(this).prop('checked', true).prop('disabled', true); } else { $('input[type="checkbox"]', thisQuestion).not(this).prop('disabled', false); } // Fire Expression Manager $('input[type="checkbox"]', thisQuestion).not(this).each(function(i) { checkconditions(this.value, this.name, this.type); }); }); // Re-enable checkboxes so data gets stored $('#moveprevbtn, #movenextbtn, #movesubmitbtn').on('click', function(){ $('input[type="checkbox"]', thisQuestion).prop('disabled', false); }); }); </script>
Sample survey attached:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The following user(s) said Thank You: blocka
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10103
- Thank you received: 3591
6 years 7 months ago #158351
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 Multiple choice - check all options
...added to the Workarounds section -
manual.limesurvey.org/Workarounds:_Manip...2All_of_the_above.22
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
- Offline
- Platinum Member
Less
More
- Posts: 409
- Thank you received: 34
6 years 7 months ago - 6 years 7 months ago #158360
by blocka
Replied by blocka on topic Multiple choice - check all options
That's awesome! Thank you!
Is there a way that if the last option is clicked again, all items would be unchecked (toggled)?
Also, in your example survey, you have :
-> Array filter exclusion: populated with "Q1"
-> Subquestion "Select All" : has a blank Relevance equation
Is there a reason for the above, or just artifacts that aren't required?
Is there a way that if the last option is clicked again, all items would be unchecked (toggled)?
Also, in your example survey, you have :
-> Array filter exclusion: populated with "Q1"
-> Subquestion "Select All" : has a blank Relevance equation
Is there a reason for the above, or just artifacts that aren't required?
Last edit: 6 years 7 months ago by blocka.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10103
- Thank you received: 3591
6 years 7 months ago #158363
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 Multiple choice - check all options
1)
2) Artifacts - ignore them.
Code:
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:complete',function() { // Identify this question var thisQuestion = $('#question{QID}'); // Initial states if($('input[type="checkbox"]:last', thisQuestion).is(':checked')) { $('input[type="checkbox"]', thisQuestion).not(':last').prop('checked', true).prop('disabled', true); } // Listener on the last checkbox $('input[type="checkbox"]:last', thisQuestion).on('change', function(e) { if($(this).is(':checked')) { $('input[type="checkbox"]', thisQuestion).not(this).prop('checked', true).prop('disabled', true); } else { $('input[type="checkbox"]', thisQuestion).not(this).prop('checked', false).prop('disabled', false); } // Fire Expression Manager $('input[type="checkbox"]', thisQuestion).not(this).each(function(i) { checkconditions(this.value, this.name, this.type); }); }); // Re-enable checkboxes so data gets stored $('#moveprevbtn, #movenextbtn, #movesubmitbtn').on('click', function(){ $('input[type="checkbox"]', thisQuestion).prop('disabled', false); }); }); </script>
2) Artifacts - ignore them.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.