Welcome to the LimeSurvey Community Forum

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

Multiple choice - check all options

More
14 years 4 months ago #80943 by user27257_d
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 topic has been locked.
More
14 years 4 months ago #80953 by DenisChenu
Hello,

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 support - Plugins, theme and development .
I don't answer to private message.
The topic has been locked.
More
14 years 3 months ago #81896 by user27257_d
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.
More
14 years 3 months ago #81993 by Mazi
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
survey-consulting.com
offlinesurveys.com
Feel free to contact me by email for professional LimeSurvey support!
The topic has been locked.
More
14 years 3 months ago #82079 by tpartner
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.
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: user27257_d, Gibouille
The topic has been locked.
More
14 years 1 month ago #84624 by user27257_d
tpartner, thank you very much, that did exactly what I was trying to accomplish!
The topic has been locked.
More
9 years 3 weeks ago - 9 years 3 weeks ago #158316 by blocka
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.
Last edit: 9 years 3 weeks ago by blocka.
The topic has been locked.
More
9 years 3 weeks ago #158350 by tpartner
In version 2.67.x, this script will render the last checkbox as a "Select all" item.

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:

File Attachment:

File Name: limesurvey...9-06.lss
File Size:17.75 KB

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: blocka
The topic has been locked.
More
9 years 3 weeks ago #158351 by tpartner

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 3 weeks ago - 9 years 3 weeks ago #158360 by blocka
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?
Last edit: 9 years 3 weeks ago by blocka.
The topic has been locked.
More
9 years 3 weeks ago #158363 by tpartner
1)
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.
Moderators: tpartner, holch

Lime-years ahead

Online-surveys for every purse and purpose