Welcome to the LimeSurvey Community Forum

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

Ranking question filtering

More
5 years 8 months ago #192383 by tpartner
Replied by tpartner on topic Ranking question filtering
In 3.x versions, you will need to deactivate AJAX in the survey theme options and use this code:

Code:
<script type="text/javascript" charset="utf-8">  
  $(document).on('ready pjax:scriptcomplete',function(){
 
    // Identify the questions
    var qHidden = $('#question{QID}');
    var qHiddenID = $(qHidden).attr('id').replace(/question/, '');
 
    // Hide the checkbox question
    qHidden.css({
        'position': 'absolute',
        'left': '-9999em'
    });
 
    // The ranking answer codes relevant for the various values of "Branch"
    // EDIT HERE AS REQUIRED
    var answerCodes = {
      1: ['101', '102', '103', '104'], // Seen by "Rangers"
      2: ['101', '102', '103', '104', '105', '106'], // Seen by "Pathfinders"
      3: ['101', '102', '103', '104', '105', '106', '107', '108'] // Seen by everybody else
    }
 
    // Get the value of the "Branch" question
    var branch = '{Branch}';
 
    // Define which set of ranking answer codes to display
    if(branch == 'Ranger') {
      var codeArray = answerCodes[1];
    }
    else if(branch == 'Pathfinder') {
      var codeArray = answerCodes[2];
    }
    else {
      var codeArray = answerCodes[3];
    }
 
    // Toggle the appropriate checkboxes and fire Expression Manager
    $('.question-item input:hidden', qHidden).val('');
    $('input:checkbox[id$="X'+qHiddenID+this+'"]').prop('checked', false).trigger('change');
    $(codeArray).each(function(i) {
      var thisInput = $('input:checkbox[id$="X'+qHiddenID+this+'"]');
      thisInput.nextAll('input:hidden').val('Y');
      thisInput.prop('checked', true).trigger('change');
    });
    });
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...8582.lss
File Size:25.55 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.
More
5 years 8 months ago #192386 by bcjewel
Replied by bcjewel on topic Ranking question filtering
Thank you! I'm back in business! I truly appreciate your prompt response.

Julie
The topic has been locked.
More
5 years 8 months ago #192387 by Joffm
Replied by Joffm on topic Ranking question filtering
Hi,
let me join the conversation.

Is there a special reason to use javascript, and not an equation to set the relevant items in the hidden multiple question?

Like this:

File Attachment:

File Name: limesurvey...82_J.lss
File Size:26.49 KB


Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
More
5 years 8 months ago #192390 by tpartner
Replied by tpartner on topic Ranking question filtering
Nope, both will work.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose