Welcome to the LimeSurvey Community Forum

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

Last Option In Array (Numbers) (Checkboxes) Column Excludes All Others

  • tarantel999
  • tarantel999's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 2 months ago #131738 by tarantel999
There was a good solution for using exclusive option in checkbox array with forcing the last row to act as exclusive. Is there an easy fix to make it work in columns? So the last row would have exclusive options for the whole column?

Solution for exclusion in rows:
www.limesurvey.org/forum/can-i-do-this-w...-excludes-all-others
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 2 months ago #131746 by tpartner
What version of LimeSurvey are you using?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • tarantel999
  • tarantel999's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 2 months ago #131747 by tarantel999
2.05 mostly, tried 2.50 today hoping that it would solve it :)
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 2 months ago #131748 by tpartner
Okay, this should work for 2.05 - 2.50.

Code:
<script type="text/javascript" charset="utf-8">    
  $(document).ready(function() {  
 
    // Identify this question
    var thisQuestion = $('#question{QID}');
 
    // Assign row-specific classes
    $('tr.subquestions-list:not(:last) td.question-item', thisQuestion).addClass('non-exclusive');
    $('tr.subquestions-list:last td.question-item', thisQuestion).addClass('exclusive');  
    // Assign column-specific classes
    $('tr.subquestions-list', thisQuestion).each(function(i){
      $('> *', this).each(function(i){
        $(this).addClass('column-'+i+'');
        $(this).attr('data-column', i);
      });
    });  
 
    // Listener on the checkboxes
    $('input[type="checkbox"]', thisQuestion).on('change', function(e) {
 
      if($(this).is(':checked')) {
        var columnNum = $(this).closest('td').attr('data-column');
        if($(this).closest('td').hasClass('exclusive')) {
          $('td[data-column="'+columnNum+'"].non-exclusive input[type="checkbox"]', thisQuestion).prop('checked', false);
          $('td[data-column="'+columnNum+'"].non-exclusive input:hidden', thisQuestion).attr('value', '');
        }
        else {
          $('td[data-column="'+columnNum+'"].exclusive input[type="checkbox"]', thisQuestion).prop('checked', false);
          $('td[data-column="'+columnNum+'"].exclusive input:hidden', thisQuestion).attr('value', '');
        }
 
        // Check relevance
        $('td[data-column="'+columnNum+'"] input[id^="answer"]', thisQuestion).each(function(i) {
          fixnum_checkconditions($(this).attr('value'), $(this).attr('id').replace(/answer/, ''), 'hidden');
        });
      }
    });
    });
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...-5-6.lss
File Size:19 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • tarantel999
  • tarantel999's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 2 months ago #131814 by tarantel999
Huge thanks!
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose