Welcome to the LimeSurvey Community Forum

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

Take marks randomly

  • Vic1107
  • Vic1107's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 8 months ago #218586 by Vic1107
Take marks randomly was created by Vic1107
Hi all,

My question to Java experts, maybe it is a complicated thing to do. The version I use is: Version 3.25.10 + 210128

What I am doing:
I have two multiple answer questions where I show multiple brands.
The first question contains the brands you know, Called Q1
The second question (called Q2) asks for your favorite brand, so the brands you know in Q1 will be displayed in Q2.
FOR THE FOLLOWING QUESTIONS THEY WILL ALWAYS APPLY FOR 3 BRANDS: THE BRAND YOU USE MOST FREQUENTLY (Q2) AND 2 BRANDS RANDOMLY THAT YOU DO KNOW (Q1).
MY PROBLEM:
I am trying to do this randomization to always take the two marks for the following questions.
In the forum I found a script that does flag randomization but this works for a matrix question so it doesn't work for multiple questions.

<script type="text/javascript" charset="utf-8">        
$(document).ready(function() {
  
function shuffleArray(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;
}
        // Identify the questions
        var thisQuestion = $('#question{QID}');
        var thisQuestionID = {QID};
        var str = $('#question{QID} input[type="text"]').val();
          var arr = str.split(', ');

        // Shuffle the array
        arr=shuffleArray(arr);
        anumbers = '#' + arr.slice(0,3).join(',');
        // Load the hidden questions with items from the array
        $('#question{QID} input[type="text"]').val(anumbers);
        $('#question{QID}').hide();  

    });
</script>


I would appreciate your support to resolve if it is possible to perform this randomization,

Greetings to all
The topic has been locked.
More
2 years 8 months ago #218613 by Eliott13
Replied by Eliott13 on topic Take marks randomly
It is worth mentioning that the script you share works in version 2X according to the publication.

It will not work for you either in a version 3.25 which is the one you are using. :)

Maybe @tpartner has something in your versionx
The topic has been locked.
  • Vic1107
  • Vic1107's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 8 months ago #218617 by Vic1107
Replied by Vic1107 on topic Take marks randomly
Thanks @Eliott,

Searching the forum I found this post, it works fine, and selects two brands at random.

forums.limesurvey.org/forum/can-i-do-thi...tion?start=15#194648

All good so far, however I tried to write this script to my survey but it didn't work, I guess for version 3.25 it doesn't work as you mentioned above. :)

Here is a test survey lss in case anyone finds something that can help.

I appreciate any help or suggestion that may be useful. :)
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 8 months ago #218631 by tpartner
Replied by tpartner on topic Take marks randomly
Do you have permissions to insert JavaScript?

Did the sample survey from the link you provided 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.
  • Vic1107
  • Vic1107's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 8 months ago #218642 by Vic1107
Replied by Vic1107 on topic Take marks randomly
Hi, Tony,

You are absolutely right, something so simple I forgot. :)

I tell you that I already managed to execute it as I was looking for it.

But at the time of doing some tests I realized that something does not fit me.

These are two text questions that host the random responses.
I used them in the following questions with a relevant equation where each sub-question shows the following:

in subquery 1 qHidden_SQ001 == 1 or qHidden_SQ002 _ == 1

in subquery 2 qHidden_SQ001 == 2 or qHidden_SQ002 _ == 2


As I mentioned before. From this question, where they select the brand, I must show 3 brands, the most frequent brand in Q2 and 2 random ones in Q1.

My problem:

Suppose that in Q1 I select three brands 4, 5 and 6, the random brands give me 5 and 6 so far.
But if I select in Q2 any brand that has already given me randomly, let's say brand 5 for obvious reasons it no longer shows me three brands selected in Q3, it is only asking me for the two marked. by the 5 and 6 mark again.

My question:
It may be possible that if in Q2 they select one of the same random marks from Q1
Can you take a third? That is, instead of taking marks 5 and 6, take marks 4 and 6, removing mark 5 that you selected in Q2.

I hope you have understood me a little
:)
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 8 months ago #218646 by tpartner
Replied by tpartner on topic Take marks randomly
Why is Q2 a multiple-choice?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • Vic1107
  • Vic1107's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 8 months ago #218655 by Vic1107
Replied by Vic1107 on topic Take marks randomly
Hi, Tony,

How to use the matrix filter for those questions. I cannot filter a radio question with a multiple choice question.

So both are multiple and in question Q2 I have all 20 brands as an exclusive option.


Regards :)
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 8 months ago #218666 by tpartner
Replied by tpartner on topic Take marks randomly
You can filter a list-radio question on a multiple-choice question - manual.limesurvey.org/Question_type_-_Li...r_.28array_filter.29

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: DenisChenu
The topic has been locked.
  • Vic1107
  • Vic1107's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 8 months ago #218678 by Vic1107
Replied by Vic1107 on topic Take marks randomly
Hi, Tony,

Excuse me, I did not know how to explain very well,

I mean something inverted, that is, the radio questions cannot make the filter to a Multiple.

As a next question refers to the brand that I would never buy, then I must use an exclusion filter to remove the favorite brand.

and if Q2 has a single response, it cannot make the filter.

Thanks
The topic has been locked.
  • holch
  • holch's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 8 months ago #218680 by holch
Replied by holch on topic Take marks randomly
On the multiple question you can use a relevance equation on each of the subquestions of the multiple answer question and hide the respective subquestion if it is the favorite brand from the single choice question.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose