Welcome to the LimeSurvey Community Forum

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

Can i choose one random sub-question from a question?

More
8 years 9 months ago #122827 by itcom
Hello !

I have a group of 8 questions, each question contains 7 sub-question of Array (1-10 scale).

Each time i present the survey, i want the system to choose randomly only one sub-question from each question. Meaning, the survey will show in the group 8 sub-questions, each ones belongs to different question.

Its is possible to do ?

Thanks for your help
The topic has been locked.
  • gabrieljenik
  • gabrieljenik's Avatar
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
8 years 9 months ago #122829 by gabrieljenik
I don't think I fully understand your question. For each question, you want to show only some options?

This link may help you: www.limesurvey-consulting.com/how-to-ran...a-limesurvey-survey/

If not fully apply, you could do some CSS & Jquery to read the random value and hide all subquestions not matching.
Either by traversing and using selectors in jquery or by using the xx-nth child notation.

Anyway, some development would be needed.

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Checkout our Reporting Solutions and our plugin shop at www.encuesta.biz .

The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 9 months ago #122830 by tpartner
In the latest version you can place relevance on sub-questions so you could use Expression Manager to load 8 Equation type questions with random numbers and use those in the relevance settings.

In previous versions you will need to use JavaScript to hide the sub-questions (and, if mandatory, click a hidden "N/A" option). Sadly, l cannot give an example of code today from my phone.

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
8 years 9 months ago #122831 by itcom
Thank you very much for the quick answer.

Screenshot attached.

tpartner, I will glad to get a code for the Javascript.

gabrieljenik, for each question i have 7 sub-questions. I want to be able to randomly show one of the sub-questions.
The link discussing on the Questions themselves. I looking to randomly show the subquestions.

Again, Thanks !
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 9 months ago - 8 years 9 months ago #122836 by tpartner
Okay, if using LS 2.05, you will need to...

1) Set up your survey to use JavaScript .

2) Add an "N/A" option to the x-scale answers for the arrays. (you will need to use normal array type questions, not array-10-point-choice type)

3) Place these functions in template.js (I think the comments adequately explain what's going on):
Code:
// A function to randomly display one row of an array type question
function showRandomRow(qid) {
 
  // Identify this question
  var thisQuestion = $('#question'+qid);
 
  // Hide the "N/A" column
  $('table.subquestions-list tr > :last-child', thisQuestion).addClass('na-column').hide();
 
  // If question not previously seen...
  if($('.na-column input.radio:checked', thisQuestion).length == 0) {      
    // Hide all answer rows
    $('tr.answers-list', thisQuestion).hide();
 
    // Create an array of answer row IDs
    var rowIDs = [];
    $('tr.answers-list', thisQuestion).each(function(i) {
      rowIDs.push($(this).attr('id'));
    });
 
    // Shuffle the array
    rowIDs = $.shuffle(rowIDs);
 
    // Show the first row in the array
    $('#'+rowIDs[0]).removeClass('array1').addClass('array2').show();
 
    // Click "N/A" in all hidden rows
    $('tr.answers-list:hidden .na-column input.radio', thisQuestion).trigger('click');
  }
  // If question previously seen...
  else {      
    // Hide answer rows that have "N/A" clicked 
    $('.na-column input.radio:checked', thisQuestion).closest('tr.answers-list').hide();
  }
}
 
// A function to shuffle elements or contents of arrays
(function($){
  $.fn.shuffle = function() {
    return this.each(function(){
      var items = $(this).children();
      return (items.length)
        ? $(this).html($.shuffle(items))
        : this;
    });
  }
 
  $.shuffle = function(arr) {
    for(
      var j, x, i = arr.length; i;
      j = parseInt(Math.random() * i),
      x = arr[--i], arr[i] = arr[j], arr[j] = x
    );
    return arr;
 
  }
})(jQuery);

4) In the source of every question you want randomized in this way, call the function like this:
Code:
<script type="text/javascript" charset="utf-8">    
  $(document).ready(function() {  
    showRandomRow({QID});  
  });
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 8 years 9 months ago by tpartner.
The topic has been locked.
More
8 years 9 months ago #122847 by itcom
Thank you very much.
I'm using an older version then LS 2.
I was able to turn on Javascript, test it well, and also put the codes you gave me.
When i running the survey, nothing happening. All the subquestions are there.
In quick debug check, seems like the script is running with no bugs.

Any thoughts? maybe is only LS version issues?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 9 months ago #122849 by tpartner
This is definitely a version issue. Versions that old lack many features and may have security issues. Can you update?

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
8 years 9 months ago #122850 by itcom
Only manually. The 3-click auto update is making me errors.
I will update the version soon and report.

Again, thank you very much.
The topic has been locked.
More
8 years 8 months ago #122977 by itcom
Ok.
Updated to the newest version, followed all steps.
Generally, the function is working but when i test the survey, the text of the survey and the radio buttons are gone:
old.risebeyond.org/evaluation_new/index.php/377136?newtest=Y

When trying another theme, its not working and show me a Java Console error:
Uncaught ReferenceError: showRandomRow is not defined

Any thoughts?
I should note that both of themes were imported and modified from an older version of LS.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 8 months ago - 8 years 8 months ago #122982 by tpartner
Try it with a new copy of the shipped default template.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 8 years 8 months ago by tpartner.
The topic has been locked.
More
8 years 8 months ago #122983 by itcom
Thanks
I have tried it and still the same. No text and no radio buttons. This is the link with a copy of the new LS version default temp:
old.risebeyond.org/evaluation_new/index.php/377136?newtest=Y
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 8 months ago #122984 by tpartner
Probably because you are using the built-in "No Answer" setting which is clicked by default. Disable that and insert your own "N/A" option.

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