Welcome to the LimeSurvey Community Forum

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

Search Results (Searched for: exclusive-item)

27 Nov 2024 18:07
In version 5.x, add an "N/A" answer to scale-2 and insert this script:

Code:
<script type="text/javascript" data-author="Tony Partner">
 
  $(document).on('ready pjax:scriptcomplete',function() {
 
        // Identify this question
        var thisQuestion = $('#question{QID}');
 
        // Identify the "exclusive" column(s)
        // Multiple columns separated by commas
        var exclusiveCols = [1,2];
 
        // Assign classes to various elements
        $('tr[id^="javatbd"]', thisQuestion).each(function(i){
            var column = 1;
            var scale = 1;
            $('td', this).each(function(i) {
                if($(this).hasClass('answer-item')) {
                    $(this).addClass('scale-'+scale+' column-'+column+'');
                    column++;
                }
                else if(scale == 1 &amp;&amp; $(this).hasClass('dual_scale_separator')) {
                    column = 1;
                    scale = 2;
                }
                else if(scale == 2 &amp;&amp; $(this).hasClass('dual_scale_separator')) {
                    column = 1;
                    scale = 3;
                }
            });
            $('td.scale-2:last', this).addClass('na-item');
        });
        $(exclusiveCols).each(function(i) {
          $('td.scale-1.column-'+this, thisQuestion).addClass('exclusive-item');
        });
 
        // Hide the "N/A" column
        var naIndex = $('td.na-item:eq(0)', thisQuestion).index();
        $('td.na-item', thisQuestion).hide();
        $('.questions-list .dsheader:last', thisQuestion).attr('colspan', Number($('.questions-list thead tr.groups .dsheader:last', thisQuestion).attr('colspan'))-1);
        $('.questions-list thead tr:not(.groups) th.answer-text:not(.noanswer-text):last', thisQuestion).hide();
        $('colgroup.group-2 col:last', thisQuestion).hide();
 
        // Listener on the radios
        $('td.scale-1 input:radio', thisQuestion).on('click', function(e) {
            var thisCell = $(this).closest('td');
            var thisRow = thisCell.closest('tr');
            var thisNA = $('.na-item input:radio', thisRow);
            var naValue = '';
            if(thisCell.hasClass('exclusive-item')) {
                naValue = thisNA.val();
                thisNA.trigger('click');
                $('td.scale-2:not(.na-item) input:radio', thisRow).prop('disabled', true);
            }
            else {
                thisNA.prop('checked', false);
                $('td.scale-2:not(.na-item) input:radio', thisRow).prop('disabled', false);
            }
            // Fire ExpressionScript
            naName = thisNA.attr("name");
            naName = naName.replace('#', '_');
            $("#java" + naName).val(naValue);
            ExprMgr_process_relevance_and_tailoring('change', naValue, 'radio');
        });
 
        // Initial states
        $('td.exclusive-item input:radio:checked', thisQuestion).each(function(i) {
            var thisRow = $(this).closest('tr');
            console.log(thisRow);
            $('.na-item input:radio', thisRow).trigger('click');
            $('td.scale-2:not(.na-item) input:radio', thisRow).prop('disabled', true);
        });
 
    });
</script>

Sample survey attached: 

File Attachment:

File Name: limesurvey...8547.lss
File Size:41.39 KB
Displaying 1 - 1 out of 1 results.

Lime-years ahead

Online-surveys for every purse and purpose