Randomize and subset questions from an array (10 point choice)

More
1 month 2 weeks ago #203842 by afu4500
Hello everybody
i'm a complete newbie to limesurvey.
is it possible to display 5 questions ranodmized from an array of 10 questions? how is this done?

Thanks for your help
Attachments:

Please Log in to join the conversation.

LimeSurvey Partners
More
1 month 2 weeks ago #203847 by Joffm
Hi,
first you have to generate randomly 5 out of 10 numbers.
Therefoe you create a question of type "short text" and enter the following javascript snippet in source code mode.
<script type="text/javascript" charset="utf-8">
 
function shuffle(array) {
  var currentIndex = array.length, temporaryValue, randomIndex;
 
  // While there remain elements to shuffle...
  while (0 !== currentIndex) {
 
    // Pick a remaining element...
    randomIndex = Math.floor(Math.random() * currentIndex);
    currentIndex -= 1;
 
    // And swap it with the current element.
    temporaryValue = array[currentIndex];
    array[currentIndex] = array[randomIndex];
    array[randomIndex] = temporaryValue;
  }
 
  return array;
}
 
 
$(document).on('ready pjax:scriptcomplete',function(){
// Fill the array
      var arr =["A","B","C","D","E","F","G","H","I","J"];
      arr = shuffle(arr);
      anumbers = '#' + arr.slice(0,5).join(',');
      $('#question{QID} input[type="text"]').val(anumbers).trigger('keyup');  
      $('#question{QID}').hide();
   });
</script>

You see there is initially an array with te letters "A-J".
This array is shuffled and in the next line only the first 5 elements are left.
This array is joined to a string and entered into the question
and the question is hidden.

And in your array it is only necessary to check if the string contains a certain letter.
Subquestion 1: strpos(Q1,"A">0
Subquestion 2: strpos(Q1,"B">0



File Attachment:

File Name: limesurvey...3378.lss
File Size:27 KB


Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:

Please Log in to join the conversation.

More
1 month 2 weeks ago #203869 by afu4500
Hi Joffm

Thanks for your quick response. I have inserted the code in a short text question.
Unfortunately, when I go to the survey preview, I don't see an array. Does the code create a new array or does it refer to an already created one? If so, do I need to add the ID of the created matrix to your code?

Thanks for your help

Please Log in to join the conversation.

More
1 month 2 weeks ago - 1 month 2 weeks ago #203872 by Joffm
Hi,
which array are you talking of?

The temporary created array in the javascript snippet?
You never will see this.

If you comment this line
// $('#question{QID}').hide();

you should see in the short text something like this


Or do you talk about YOUR 10-point-array?
Of course you have to create this an use the subquestion relevance I showed.


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:
Last edit: 1 month 2 weeks ago by Joffm.

Please Log in to join the conversation.

More
1 month 2 weeks ago #203874 by afu4500
Hi Joffm,

Sorry for my incomprehensible expression.
The short text question with the code shows me randomly 5 letters. This works.
But the array I created still shows all the sub-questions.
Do I also have to insert the code in the source code of the array or what does the code in the source code of the short text question do for me?

Thanks for your patience

Please Log in to join the conversation.

More
1 month 2 weeks ago #203877 by afu4500
Sorry, I didn't see your last sentence about subquestion relevance.
I adapted the subquestion relevance as seen in the photo.
There seems to be something wrong when I check the logic. What should I change?

Thanks for your help.
Attachments:

Please Log in to join the conversation.

More
1 month 2 weeks ago #203881 by Joffm
Sorry, my fault
The closing bracket doesn't work well on my keyboard.

strpos(Q1,"A")>0

as it is explained in the manual about "implemented functions".

Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

More
1 month 2 weeks ago #203883 by afu4500
Awsome thank you so much, it worked.

Do you have an idea how to add 2 fields at the end of the array,
so that the participants can write something themselves and rate it from 1-10.

Thx

Please Log in to join the conversation.

More
1 month 2 weeks ago - 1 month 2 weeks ago #203886 by Joffm
Yes
https://forums.limesurvey.org/forum/design-issues/116898-array-with-textfield-others

You can extend to two, three, four,... others

Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 month 2 weeks ago by Joffm.

Please Log in to join the conversation.

More
1 month 2 weeks ago #203887 by afu4500
I really appreciate your help.
Unfortunately I cannot download the attached file because the network of the company I work for does not allow it.
Can you send me the code or post it in the forum as before.

Thx

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now