Welcome to the LimeSurvey Community Forum

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

Making Columns Exclusive - Array (Numbers) (Checkbox)

  • phorcast2022
  • phorcast2022's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 week 1 day ago #265390 by phorcast2022
Please help us help you and fill where relevant:
LimeSurvey version: [see right hand bottom of your LimeSurvey admin screen]
Own server or LimeSurvey Cloud:
Survey theme/template:
==================
(Write here your question/remark)Please help us help you and fill where relevant:
LimeSurvey version: [see right hand bottom of your LimeSurvey admin screen]
Own server or LimeSurvey Cloud:
Survey theme/template:
==================
(Write here your question/remark)Please help us help you and fill where relevant:
LimeSurvey version: LimeSurvey Cloud Version 6.5.13
Own server or LimeSurvey Cloud: LimeSurvey Cloud
Survey theme/template: Extended from Fruity
==================
Hello,

I used the following code to make one of my question's last two rows exclusive. I was wondering if someone could help me do the same thing but instead make the last two columns exclusive, please?

Thank you!<script type="text/javascript" data-author="Tony Partner">
$(document).on('ready pjax:scriptcomplete',function(){
 
var thisQuestion = $('#question{QID}');
var firstRow = $('tr.subquestion-list:eq(0)', thisQuestion);
 
// Listener on the first row checkboxes
$(':checkbox', firstRow).on('change', function(e){
$(':checkbox', thisQuestion).prop('disabled', false);
 
if($(this).is(':checked')) {
var thisCell = $(this).closest('td');
var thisIndex = $(thisCell).index();
 
// Render this checkbox exclusive in this row
var otherRowCells = $('td.answer-item', firstRow).not(thisCell);
$(otherRowCells). each (function(i) {
$('input[type="hidden"]', this).val('');
$(':checkbox', this).prop('checked', false).trigger('change');
});
 
// Render this checkbox exclusive in this column
var otherColCells = $('td.answer-item:nth-child('+(thisIndex+1)+')').not(thisCell);
$(otherColCells). each (function(i) {
$('input[type="hidden"]', this).val('');
$(':checkbox', this).prop('checked', false).trigger('change').prop('disabled', true);
});
}
});
});
</script>

 

File Attachment:

File Name: limesurvey...7932.lss
File Size:37 KB

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 week 3 hours ago #265417 by Joffm
Hi,
I am sure you will find the script to make the last column exclusive many times in the forum.

As I am not very familiar with javascript I just doubled the exclusive cells with classes "exlusive-item1" and "exlusive-item2"
Code:
<script type="text/javascript" charset="utf-8">
  $(document).ready(function() {
    // Call the exclude function using question ID
    excludeOpt({QID});
  });
 
  // A function to make the last option in each array row exclusive
  function excludeOpt (qID) {
 
    var thisQuestion = $('#question'+qID)
 
    // Add some classes to the checkbox cells
    $('td.checkbox-item', thisQuestion).addClass('normal-item');
    $('tr.subquestion-list', thisQuestion).each(function(i) {
    $('.normal-item:last', this).removeClass('normal-item').addClass('exlusive-item1')
    $('.normal-item:eq(-1)', this).removeClass('normal-item').addClass('exlusive-item2')
    });
 
    // A listener on the checkboxes
    $('input[type="checkbox"]', thisQuestion).on('change', function (event) {
      handleExclusive($(this).closest('td'));
    });
 
    function handleExclusive(thisCell) {
 
      var thisRow = $(thisCell).closest('tr');
 
      // Uncheck the appropriate boxes in a row
      if ($(thisCell).hasClass('normal-item')) {
        $('.exlusive-item1 input[type="checkbox"]', thisRow).prop('checked', false);
        $('.exlusive-item2 input[type="checkbox"]', thisRow).prop('checked', false);
      }
      else if ($(thisCell).hasClass('exlusive-item1')) {
        $('.exlusive-item2 input[type="checkbox"]', thisRow).prop('checked', false);
        $('.normal-item input[type="checkbox"]', thisRow).prop('checked', false);
      }  
      else if ($(thisCell).hasClass('exlusive-item2')) {
        $('.exlusive-item1 input[type="checkbox"]', thisRow).prop('checked', false);
        $('.normal-item input[type="checkbox"]', thisRow).prop('checked', false);
      }  
      else {
        $('.normal-item input[type="checkbox"]', thisRow).prop('checked', false);
      }
 
      // Check conditions (relevance)
      $('td.checkbox-item', thisRow).each(function(i) {
        var thisValue = '';
        if($('input[type="checkbox"]', this).is(':checked')) {
          thisValue = 1;
        }
        var thisSGQA = $('input[type="checkbox"]', this).attr('id').replace(/cbox_/, '');
 
        $('input[type="hidden"]', this).attr('value', thisValue);
        fixnum_checkconditions(thisValue, thisSGQA, 'hidden');
      });
    }
  }
</script>

 

File Attachment:

File Name: limesurvey...32_J.lss
File Size:34 KB

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: DenisChenu

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose