Welcome to the LimeSurvey Community Forum

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

Randomization of Items

  • Co_Flo
  • Co_Flo's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 11 months ago #136048 by Co_Flo
Randomization of Items was created by Co_Flo
Dear Community,
I really like using LimeSurvey but ...actually there is no but :) . Just a rather tricky set of questions I do not achieve to implement. So maybe you can help me out:
1. I have constructed an array-type question with a scale from 1-5 (1 = very good, 5 = very bad) with a set of 10 items (subquestions)
2. The following Question is radio list which must contain the items (subquestions) of the former array question. However, it should only contain those items that were rated 3 or worse (3-5)
[This is the 1st issue I don`t get solved]
3. The radio list should also only contain maximum 5 items (subquestions) of the former array. These five items should be chosen randomly!
- e.g. so if all 10 items were rated 3 or worse in the array, LimeSurvey should randomly choose 5 of these to show up in the subsequent radio list
- e.g. if only 4 items were rated 3 or worse in the array, LimeSurvey should of course only take these 4 ot show up in the subsequent radio list
[This is the 2nd issue I don`t get solved]

Any idea how to do this? I would really appreciate your suggestion

Thanks in advance for thinking about these issues!
The topic has been locked.
  • Co_Flo
  • Co_Flo's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 11 months ago #136063 by Co_Flo
Replied by Co_Flo on topic Randomization of Items
I forgot: I am using Limesurvey Version 2.05+ Build 141229.

Cheers!
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 11 months ago - 7 years 11 months ago #136070 by tpartner
Replied by tpartner on topic Randomization of Items
Issue 1: Assuming the array and radio questions are on separate pages, perhaps a solution like this thread where we insert a hidden multiple-choice and toggle it with JavaScript. That hidden question can then be used to filter the radio question. (code modified for 2.05):

Code:
<script type="text/javascript" charset="utf-8">    
 
  $(document).ready(function(){
 
    // Define the filtering columns
    var filterColumns = [3, 4, 5];
 
    // Identify the questions
    var q1 = $('#question{QID}');
    var qHidden = $(q1).nextAll('.multiple-opt:eq(0)');
 
    // Define a few vars
    var q1ID = $(q1).attr('id').replace(/question/, '');
    var qHiddenID = $(qHidden).attr('id').replace(/question/, '');
 
    // Hide the multiple-choice
    $(qHidden).hide();
 
    // Assign some classes
    $('table.subquestions-list tr[id^=javatbd]', q1).each(function(i){
      $('> td', this).each(function(i){
        $(this).addClass('column-'+(i+1)+'');
      });
    });
    $(filterColumns).each(function(i){
      $('td.column-'+this+'').addClass('filter-cell');
    });
 
    // Listener on the Q1 cells
    $('input.radio', q1).click(function(e) {
      var thisRow = $(this).closest('tr');
      var thisCode = $(thisRow).attr('id').split('X'+q1ID)[1];
      var hiddenInput = $('input.checkbox[id$="X'+qHiddenID+thisCode+'"]', qHidden);
      setTimeout(function() {
        if($('input.radio:checked', thisRow).closest('td').hasClass('filter-cell')) {
          $(hiddenInput).attr('checked', true);
          $(hiddenInput).nextAll('input[type="hidden"]').attr('value', 'Y');
        }
        else {
          $(hiddenInput).attr('checked', false);
          $(hiddenInput).nextAll('input[type="hidden"]').attr('value', '');
        }
 
        // Check conditions/relevance
        checkconditions(hiddenInput.value, hiddenInput.name, hiddenInput.type)
      }, 250); 
    });
  });
</script>

Issue 2: Along with filtering as above, randomize the order of answers in the radio question and insert a script like this to hide all but the first 5 answers:

Code:
<script type="text/javascript" charset="utf-8">    
  $(document).ready(function() {  
 
    $('#question{QID} li.answer-item:visible:gt(4)').hide();    
  });  
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...68-2.lss
File Size:36 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 7 years 11 months ago by tpartner.
The following user(s) said Thank You: Co_Flo
The topic has been locked.
  • Co_Flo
  • Co_Flo's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 11 months ago #136082 by Co_Flo
Replied by Co_Flo on topic Randomization of Items
Hey,
thanks a lot for the quick answer. I will check and implement it the next days. Hope to get it to work based on your solution. Would the code be different for a newer version of LimeSurvey?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 11 months ago #136092 by tpartner
Replied by tpartner on topic Randomization of Items

Would the code be different for a newer version of LimeSurvey?

The jQuery selectors may be different for version 2.5. There have been some changes to the HTML in that version.

Cheers,
Tony Partner

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

Lime-years ahead

Online-surveys for every purse and purpose