Welcome to the LimeSurvey Community Forum

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

Last two Options In Array (Numbers) (Checkboxes) Excludes All Others

More
1 year 11 months ago #267781 by Acmelive
Please help us help you and fill where relevant:
Your LimeSurvey version: LimeSurvey Cloud Versión 6.6.8
Own server or LimeSurvey hosting: LimeSurvey Cloud
Survey theme/template: Vanilla
==================
Dear All,
I have a multiple array of numbers question in which I want the last two columns to be exclusive.
I usually used the solution for the last column as exclusive ( www.limesurvey.org/manual/Workarounds:_M..._Excludes_All_Others ), which works perfectly, but in this case it does not provide the complete solution.
I have searched for other solutions within the forum where I can make one or more specific columns disable the rest, but they have not worked.
Best regards.
 

Please Log in to join the conversation.

More
1 year 11 months ago - 1 year 11 months ago #267794 by tpartner
This script, placed in the question text, will render the last two columns exclusive.
 
 
Code:
<script type="text/javascript" data-author="Tony Partner"> $(document).on('ready pjax:scriptcomplete',function(){ var thisQuestion = $('#question{QID}') // Add some classes to the checkbox cells $('tr[id^="javatbd"]', thisQuestion).each(function(i) { // Last two columns exclusive $('td.checkbox-item', this).slice(-2).addClass('exclusive-item'); }); // A function to un-check boxes function resetCheckbox(thisItem) { $(':hidden', thisItem).val(''); $(':checkbox', thisItem).prop('checked', false).trigger('change'); } // A listener on the checkboxes $(':checkbox', thisQuestion).on('change', function(e) { if($(this).is(':checked')) { var thisItem = $(this).closest('.answer-item'); var thisRow = $(this).closest('tr'); var items = $('td.answer-item.exclusive-item', thisRow); if($(thisItem).hasClass('exclusive-item')) { items = $('td.answer-item', thisRow).not(thisItem); } $.each(items, function(i, el) { resetCheckbox(el); }); } }); }); </script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 1 year 11 months ago by tpartner.
The following user(s) said Thank You: Acmelive

Please Log in to join the conversation.

More
1 year 11 months ago #267806 by Acmelive
It works perfectly! You are a genius!
Thank you so much for your invaluable help!!

Please Log in to join the conversation.

Moderators: tpartner, holch

Lime-years ahead

Online-surveys for every purse and purpose