Welcome to the LimeSurvey Community Forum

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

Search Results (Searched for: removeClass)

  • squidy
  • squidy's Avatar
29 May 2025 18:02
Replied by squidy on topic Upload modal script - LS 6.x
Does anyone know how to adapt this code to work in version 6.x? 

File Attachment:

File Name: Survey - D...odal.lss
File Size:40 KB

Code:
<script type="text/javascript" data-author="Tony Partner">    
 
    $(document).on('ready pjax:scriptcomplete',function(){
 
       $("#answer{SGQ}SQ001_SQ001").mask("999.999.999-99",{ placeholder:" " });
 
      // Listener on the text input
        $('#answer{SGQ}SQ002_SQ002').on('keyup', function(e) {
            $(this).val($(this).val().toUpperCase());
            checkconditions($(this).attr('value'), $(this).attr('name'), $(this).attr('type'));
        });
      
       $("#answer{SGQ}SQ001_SQ002").val(" ");
       $("#answer{SGQ}SQ001_SQ002").hide();
      
        // Identify the questions
        var qArrayID = '{QID}';
        var qArray = $('#question'+qArrayID);
        var arrayLength = $('tr[id^="javatbd"]', qArray).length;
        var qUploads = qArray.nextAll('.upload-files:lt('+arrayLength+')');
 
        // Add some classes
        qArray.addClass('array-with-uploads-question');
        $(qUploads).addClass('d-none');
 
        // Insert the "Upload" buttons
        $('tr[id^="javatbd"] .answer-item:last-child', qArray).each(function(i) {
            $('*', this).remove();
            $(this).append('<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#upload-'+qArrayID+'-'+(i+1)+'" data-bs-backdrop="static" data-bs-keyboard="false">Anexar comprovante</button>');
        });
 
        // Loop through the upload questions
        $(qUploads).each(function(i) {
            // Create a modal
            $('body').append('<div class="modal fade upload-modal" id="upload-'+qArrayID+'-'+(i+1)+'" tabindex="-1" aria-labelledby="uploadModalLabel'+qArrayID+'-'+(i+1)+'" aria-hidden="true">\
                                <div class="modal-dialog">\
                                    <div class="modal-content">\
                                        <div class="modal-header">\
                                            <h5 class="modal-title" id="uploadModalLabel'+qArrayID+'-'+(i+1)+'">'+$('.ls-label-question', this).html()+'</h5>\
                                            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Fechar"></button>\
                                        </div>\
                                        <div class="modal-body">\
                                        </div>\
                                        <div class="modal-footer">\
                                            <button type="button" class="btn btn-primary" data-bs-dismiss="modal">OK</button>\
                                        </div>\
                                    </div>\
                                </div>\
                            </div>');
 
            // Move this question into the modal
            $('#upload-'+qArrayID+'-'+(i+1)+' .modal-body').append($(this));
            $(this).removeClass('d-none');
        });
 
        // Interrupt the Previous/Next/Submit function (to put upload questions back in the form)
        $('#limesurvey').on('submit', function(e) {
            $('.upload-modal .upload-files').appendTo($('.group-container:eq(0)')).addClass('d-none');
        });    
    });
</script>
<style data-author="Tony Partner" type="text/css">
.upload-modal .file-upload-modal.in {
        height: max-content;
    }
</style>
  • Joffm
  • Joffm's Avatar
23 Apr 2025 14:17
Here two scripts.

1. Create a "multiple short text" question after your array(numbers) question
Code:
<script type="text/javascript" charset="utf-8">
     $(document).on('ready pjax:scriptcomplete',function(){
         // Identify the questions
        var qArrayID = {QID};
        var qArray = $('#question'+qArrayID);
        var qMultiText = qArray.nextAll('.multiple-short-txt:eq(0)');
 
              // Hide the multi-short-text question
        $(qMultiText).hide();
 
        var tableWidth = $('table.questions-list:eq(0)', qArray).width();
        var answerWidth = $('col.ls-col-odd:eq(0)', qArray).width();
        var answerWidthPercent = (answerWidth/tableWidth)*100;
        var answersLength = $('col.ls-col-odd, col.ls-col-even', qArray).length;
        var answerWidthPercent2 = (answerWidthPercent*answersLength)/(answersLength+1)
        $('table.questions-list col', qArray).removeAttr('width');
        $('table.questions-list col:not(.col-answers)', qArray).css('width', 'auto');
        $('table.questions-list thead tr', qArray).append( '<th class="answer-text inserted-column-label" /></th>');
        $('table.questions-list thead tr th.answer-text.inserted-column-label', qArray).css('width','30%');
        $('tr.subquestion-list', qArray).each(function(i) {
            $(this).append('<td class="answer-item text-item">\
            </td>\
            ');
        });
        // Load the column label for the text inputs
        $('.inserted-column-label:eq(0)', qArray).text($('.ls-label-question', qMultiText).text());
        $('.text-item', qArray).append('<label class="ls-label-xs-visibility">'+$('.ls-label-question', qMultiText).text()+'</label>');
        // Loop through the multi-short-text sub-questions
        $('li.answer-item', qMultiText).each(function(i) {
            // Move the text inputs into the array
            $('input[type="text"]', this).appendTo($('tr.subquestion-list:eq('+i+') .text-item', qArray));
        });
    });
</script>
Question text of text question is the label of the "Other" option.

2. With an array(text)
Code:
<script type="text/javascript" charset="utf-8">
    
    
    $(document).on('ready pjax:scriptcomplete',function(){
 
        // Identify this question
        var thisQuestion = $('#question{QID}');
 
        // Column-specific classes
        $('tr.subquestion-list', thisQuestion).each(function(i) {
            $('th, td', this).each(function(i) {
                $(this).addClass('column-'+i);
            });
        });
        
        // Insert checkboxes
        $('.answer-item.column-1, .answer-item.column-2, .answer-item.column-3', thisQuestion).addClass('custom-checkbox-item');
        $('.custom-checkbox-item', thisQuestion).each(function(i) {
            var thisID = $('input:text:eq(0)', this).attr('id');
            $('label', this).before('<input class="" id="'+thisID+'" value="Y" type="checkbox" name="'+thisID.replace(/answer/, '')+'" />');
            if($('input:text:eq(0)', this).val() == 'Y') {
                $('input:checkbox:eq(0)', this).prop('checked', true);
            }
            $(this).removeClass('text-item').addClass('checkbox-item');
            $('input:text:eq(0)', this).remove();
        });      
    });
</script>


By the way:
Why do you ask all your questions in catagory "Installation and Update" though they are not related to this?
In my opinion you should ask in "Can I do this with LimeSurvey?"
  • percyherrera
  • percyherrera's Avatar
04 Apr 2025 01:36
Ayúdenos a ayudarle y rellene los siguientes campos:.
Su versión de LimeSurvey: 6.12.3
Servidor propio o LimeSurvey Cloud: LimeSurvey Cloud
Plantilla de diseño utilizada: vanilla
==================
Amigos, comparto el siguiente script que utilizo para el siguiente escenario: Imaginemos que tenemos una pregunta de tipo respuesta multiple con varios items en una columna y en el ultimo campo tenemos la opción "Ninguno" o "N/A". La idea es que si selecciono el item "Ninguno" se desmarquen los otros items y si selecciono cualquiera de los items validos se desmarque la opción "Ninguno" si estuviera seleccionada.  Esto lo he podido lograr con el siguiente script y lo comparto para usarlo en un futuro.
Espero sea de ayuda:
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 a single-column multiple choice exclusive
  function excludeOpt(qID) {
    var thisQuestion = $('#question' + qID);
 
    // Add classes to the checkbox items
    $('input[type="checkbox"]', thisQuestion).each(function(i) {
      $(this).closest('li').addClass('normal-item');
    });
 
    // Mark the last checkbox as exclusive
    $('li.normal-item:last', thisQuestion).removeClass('normal-item').addClass('exclusive-item');
 
    // A listener on the checkboxes
    $('input[type="checkbox"]', thisQuestion).on('change', function(event) {
      handleExclusive($(this).closest('li'));
    });
 
    function handleExclusive(thisItem) {
      // Uncheck the appropriate boxes
      if ($(thisItem).hasClass('normal-item')) {
        $('.exclusive-item input[type="checkbox"]', thisQuestion).prop('checked', false);
      } else {
        $('.normal-item input[type="checkbox"]', thisQuestion).prop('checked', false);
      }
 
      // Check conditions (relevance)
      $('li.checkbox-item', thisQuestion).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>
  • Joffm
  • Joffm's Avatar
19 Feb 2025 16:30 - 19 Feb 2025 19:22

However, there is still a bit mistake.

No, it is not.
As you see the script runs when the page is loaded
$(document).ready(function() { 
This means it doesn't take into account what happened before.

You have to rethink your design.

I could propose:
  • Use an array text with four columns
  • Preset the first column of row 1 and row 2 by an expression
  • Disable these two fields
  • Optionally enter a header for the "Others"
  • Show the next "Other" row, if the count of the previous row is equal to 4.






Scripts:
To enter the dropdowns you have to use a different script that takes in account the used columns (no dropdown in the first column)
Code:
<script type="text/javascript" charset="utf-8">
  $(document).on('ready pjax:scriptcomplete',function(){
    var thisQuestion = $('#question{QID}');
 
    // Insert selects
    $('.answer-item.answer_cell_X002', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\
  <option value="">Please choose...</option>\
<option value="1">very low</option>\
<option value="2">low</option>\
<option value="3">medium</option>\
<option value="4">good</option>\
<option value="5">very good</option>\
    </select>');
    $('.answer-item.answer_cell_X003', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\
 <option value="">Please choose...</option>\
<option value="1">very low</option>\
<option value="2">low</option>\
<option value="3">medium</option>\
<option value="4">good</option>\
<option value="5">very good</option>\
    </select>');  
    $('.answer-item.answer_cell_X004', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\
 <option value="">Please choose...</option>\
<option value="1">very low</option>\
<option value="2">low</option>\
<option value="3">medium</option>\
<option value="4">good</option>\
<option value="5">very good</option>\
    </select>');
 
   // Listeners
    $('.inserted-select', thisQuestion).on('change', function(i) {
      if($(this).val() != '') {
        $(this).closest('.answer-item').find('input:text').val($('option:selected', this).val()).trigger('change');
      }
      else {
        $(this).closest('.answer-item').find('input:text').val('').trigger('change');
      }
    });
     // Returning to page
    $('.with-select input:text', thisQuestion).each(function(i) {
      var thisCell = $(this).closest('.answer-item');
      var inputText = $.trim($(this).val());
      $('select.inserted-select', thisCell).val(inputText);
    });
 
   // Clean-up styles
    $('select.inserted-select', thisQuestion).css({
      'max-width': '100%'
    });
    $('.with-select input:text', thisQuestion).css({
      'position': 'absolute',
      'left': '-9999em'
    });
  });
</script>


To disable the two fields
Code:
<script type="text/javascript" charset="utf-8">
  $(document).on('ready pjax:scriptcomplete',function(){
    $("#answer{SGQ}Y001_X001").prop('disabled', true);
    $("#answer{SGQ}Y002_X001").prop('disabled', true);
  });
</script>


To insert the additional header
Code:
<script type="text/javascript" charset="utf-8">        
    $(document).ready(function() {
       // Identify this question
      var thisQuestion = $('#question{QID}');
      // Define the sub-heading text strings
      var subHeading1 = '<span style="color:maroon;font-size:12pt;font-weight:bold">Others (optional)</span>';
      var columnsLength = $('tr.subquestion-list:eq(0) > *', thisQuestion).length;
        // Insert the new rows
        $('tr.subquestion-list:eq(2)', thisQuestion).before('<tr class="sub-header-row"><th colspan="'+columnsLength+'">'+subHeading1+'</th></tr>');
        // Fix up the row classes
      var rowClass = 1;
      $('table.subquestions-list tbody tr', thisQuestion).each(function(i) {
            if($(this).hasClass('sub-header-row')) {
                rowClass = 1
            }
            else {
                rowClass++;
            $(this).removeClass('array1 array2')
            if(rowClass % 2 == 0) {
                $(this).addClass('array2');
            }
            else {
                $(this).addClass('array1');
                }
            }
        });
    });
</script>


And to preset the two fields 

{Q2_Y001_X001='Employee 1'}
{Q2_Y002_X001='Employee 2'}


Joffm
 
  • tpartner
  • tpartner's Avatar
13 Jan 2025 14:45
Replied by tpartner on topic Array - multiple choice and single choice

...but was unsuccessfully able to make one of my subquestions exclusive per column.
See this post - forums.limesurvey.org/forum/can-i-do-thi...th-checkboxes#227597

If you want the last column to be exclusive, change this:
Code:
$('tr[id^="javatbd"]:first td.checkbox-item', thisQuestion).removeClass('normal-opt').addClass('exclusive-opt');

To this:
Code:
$('tr[id^="javatbd"]:last td.checkbox-item', thisQuestion).removeClass('normal-opt').addClass('exclusive-opt');
  • gerism81
  • gerism81's Avatar
27 Nov 2024 10:03
Replied by gerism81 on topic Se puede adaptar con JAVASCRIPT?
Aquí dejo el código utilizado hasta ahora que no termina de funcionar en lo relacionado con las fechas:

<script>
$(document).on('ready pjax:scriptcomplete', function () {
var thisQuestion = $('#question{QID}');
var today = new Date().toISOString().split('T')[0]; // Fecha actual en formato yyyy-mm-dd

// Limitar la fecha máxima al día actual
thisQuestion.find('input[type="date"]').attr('max', today);

// Validar que la fecha de fin no sea anterior a la de inicio
thisQuestion.find('.answer-item.answer_cell_b').on('change', function () {
var startDate = $(this).closest('tr').find('.answer-item.answer_cell_a input').val();
var endDate = $(this).val();

if (startDate && endDate && startDate > endDate) {
alert('La fecha de fin no puede ser anterior a la fecha de inicio.');
$(this).addClass('error');
} else {
$(this).removeClass('error');
}
});

// Insertar la fecha actual si "Sigue de baja" está seleccionado
$('#answerp19').on('change', function () {
if ($(this).val() === '1') { // 1: Sigue de baja
var numBaixes = parseInt($('#answerp20').val(), 10); // Número de bajas
if (!isNaN(numBaixes) && numBaixes > 0) {
var lastRow = thisQuestion.find('table tbody tr').eq(numBaixes - 1).find('.answer-item.answer_cell_b input');
lastRow.val(today); // Configura la fecha actual
lastRow.attr('readonly', true); // Hace que el campo no sea editable
lastRow.removeClass('error');
}
} else {
thisQuestion.find('input[type="date"]').attr('readonly', false); // Permite editar las fechas nuevamente
}
});

// Validación para evitar fechas duplicadas
thisQuestion.find('input[type="date"]').on('change', function () {
var dates = [];
var hasDuplicates = false;

thisQuestion.find('input[type="date"]').each(function () {
var dateVal = $(this).val();
if (dateVal) {
if (dates.includes(dateVal)) {
hasDuplicates = true;
}
dates.push(dateVal);
}
});

if (hasDuplicates) {
alert('Las fechas no pueden estar duplicadas.');
$(this).addClass('error');
} else {
$(this).removeClass('error');
}
});

// Estilo para campos con error
$('head').append('<style>.error { border-color: red; }</style>');
});
</script>
  • Joffm
  • Joffm's Avatar
13 Nov 2024 14:16 - 13 Nov 2024 14:17
Use your own "headers.
Code:
<script type="text/javascript" charset="utf-8">        
    $(document).ready(function() {
      // Identify this question
      var thisQuestion = $('#question{QID}');
      // Define the sub-heading text strings
      var subHeading = '<th></th><th>1</th><th>2</th><th>3</th><th>4</th><th>5</th>';
      var columnsLength = $('tr.answers-list:eq(0) > *', thisQuestion).length;
       // Insert the new rows
       $('tr.answers-list:eq(1)', thisQuestion).before('<tr class="sub-header-row">'+subHeading+'</tr>');
       $('tr.answers-list:eq(2)', thisQuestion).before('<tr class="sub-header-row">'+subHeading+'</tr>');
       $('tr.answers-list:eq(3)', thisQuestion).before('<tr class="sub-header-row">'+subHeading+'</tr>');
       // For all subquestions - or however you want
       // Fix up the row classes
      var rowClass = 1;
      $('table.subquestions-list tbody tr', thisQuestion).each(function(i) {
            if($(this).hasClass('sub-header-row')) {
                rowClass = 1
            }
            else {
                rowClass++;
            $(this).removeClass('array1 array2')
            if(rowClass % 2 == 0) {
                $(this).addClass('array2');
            }
            else {
                $(this).addClass('array1');
                }
            }
        });
    });
</script>


And some styling

Code:
<style type="text/css">
.sub-header-row {
  color: maroon;
  font-weight:bold;
  text-align: center;
  }
</style>


 

Joffm
  • Joffm
  • Joffm's Avatar
01 Aug 2024 17:20 - 01 Aug 2024 17:21
Hi,
you saw that this script is more than 9 years old and was made for a totally different version?

You may use this
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-item')
    });
 
    // 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-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>


To make the first column exclusive just exchange
$('.normal-item:last', this).removeClass('normal-item').addClass('exlusive-item')
by
$('.normal-item:first', this).removeClass('normal-item').addClass('exlusive-item')
Joffm
 
  • Joffm
  • Joffm's Avatar
24 Jul 2024 12:07
Hi, 
you asked this more than 2 years ago
[url] forums.limesurvey.org/forum/can-i-do-thi...upgrade-to-version-5 [/url]
You only have to adapt.



I only changed the question type to "long text", and in the script the reference from "upload-files" to "text-long". (and all other mentions of "upload" to "comment" for better readability)
Code:
<script type="text/javascript" data-author="Tony Partner">        
    $(document).on('ready pjax:scriptcomplete',function(){
         // Identify the questions
        var qArrayID = '{QID}';
        var qArray = $('#question'+qArrayID);
        var arrayLength = $('tr[id^="javatbd"]', qArray).length;
        var qComments = qArray.nextAll('.text-long:lt('+arrayLength+')');
 
        // Add some classes
        qArray.addClass('array-with-comments-question');
        $(qComments).addClass('hidden');
      
        // Insert the "Upload" buttons
        $('tr[id^="javatbd"] .answer-item:last-child', qArray).each(function(i) {
            $('*', this).remove();
            $(this).append('<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#comment-'+qArrayID+'-'+(i+1)+'" data-backdrop="static" data-keyboard="false">Comment</button>');
        });
      
        // Loop through the upload questions
        $(qComments).each(function(i) {
            // Create a modal
            $('body').append('<div class="modal comment-modal" id="comment-'+qArrayID+'-'+(i+1)+'" tabindex="-1" role="dialog">\
                                <div class="modal-dialog" role="document">\
                                    <div class="modal-content">\
                                        <div class="modal-header">\
                                            <h5 class="modal-title">'+$('.ls-label-question', this).html()+'Please, enter your comment</h5>\
                                        </div>\
                                        <div class="modal-body">\
                                        </div>\
                                        <div class="modal-footer">\
                                            <button type="button" class="btn btn-primary" data-bs-dismiss="modal">OK</button>\
                                        </div>\
                                    </div>\
                                </div>\
                            </div>');
 
            // Move this question into the modal
            $('#comment-'+qArrayID+'-'+(i+1)+' .modal-body').append($(this));
            $(this).removeClass('hidden');
        });
 
        // Interrupt the Next/Submit function (to put upload questions back in the form)
        $('#ls-button-submit').on('click', function(e) {        
            $('.comment-modal .text-long').appendTo($('.group-container:eq(0)')).addClass('hidden');
        });    
    });
</script>
<style data-author="Tony Partner" type="text/css">
    .comment-modal .comment-modal.in {
        height: max-content;
    }
</style>

And for your dynamic rows?
[url] forums.limesurvey.org/forum/design-issue...ew-answer-row#216648 [/url]

Joffm
  • Matadeleo
  • Matadeleo's Avatar
16 Jul 2024 14:10 - 16 Jul 2024 14:35
Replied by Matadeleo on topic Multiple Numeric Slider - Fixing separated label
I've managed to get it somewhere by removing the pipe/second label and using the following code to manually insert them

 
Code:
// Label 1
var label1 = $('<label class="col-12 col-md-3 slider-right">Label 1</label>');
$('#javatbd{SID}X{GID}X{QID}1 .ls-slider-item-row').append(label1);
$('#label-{SID}X{GID}X{QID}1').removeClass('col-md-4').addClass('col-md-3 mb-0');
$('#javatbd{SID}X{GID}X{QID}1 .px-md-5').removeClass('col-md-8').addClass('col-md-6');
 
// Label 2
var label2 = $('<label class="col-12 col-md-3 slider-right">Label 2</label>');
$('#javatbd{SID}X{GID}X{QID}2 .ls-slider-item-row').append(label2);
$('#label-{SID}X{GID}X{QID}2').removeClass('col-md-4').addClass('col-md-3 mb-0');
$('#javatbd{SID}X{GID}X{QID}2 .px-md-5').removeClass('col-md-8').addClass('col-md-6');
 
// Label 3
var label3 = $('<label class="col-12 col-md-3 slider-right">Label 3</label>');
$('#javatbd{SID}X{GID}X{QID}3 .ls-slider-item-row').append(label3);
$('#label-{SID}X{GID}X{QID}3').removeClass('col-md-4').addClass('col-md-3 mb-0');
$('#javatbd{SID}X{GID}X{QID}3 .px-md-5').removeClass('col-md-8').addClass('col-md-6');


If anyone is familiar with the bug reporting process, can you please create a bug report for this issue
 
  • tpartner
  • tpartner's Avatar
25 Jun 2024 11:31
See here - forums.limesurvey.org/forum/search?query...artner&childforums=1

(Scroll down to "Fix up the row background colours")
  • Joffm
  • Joffm's Avatar
20 Jun 2024 17:04
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
Displaying 1 - 12 out of 12 results.

Lime-years ahead

Online-surveys for every purse and purpose