Welcome to the LimeSurvey Community Forum

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

Random Media Loading

More
6 years 9 months ago #155547 by darty
Random Media Loading was created by darty
Hi!

I have a dataset of media files (> 2000 files), each with their own ID and metadata. I'd like to conduct a study where every user answers questions about 10 random media files.

My current idea is to have each question retrieve a random ID from an external server and link that ID to the current question group. So every question retrieves a URL from a fixed address, then parses the ID and the media URL from the response, completes the ID into a hidden field and includes the media file in the webpage.

I'm not sure if this is the correct way to proceed with this, and I was wondering if someone could point me in the right direction to achieve this.

Thank you!
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 9 months ago #155553 by holch
Replied by holch on topic Random Media Loading
You could create a random number via Expression Manager (there are many examples here in the forum on how to do that).
You would have to create as many equation questions and save random numbers into them as you will want to show files per user (in your case 10).
Only problem: There is a slight chance that you could get a file more than once per user.

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.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 9 months ago #155566 by tpartner
Replied by tpartner on topic Random Media Loading
You can use JavaScript to load the inputs of a multiple-numeric question and then use those values in your paths to the videos.

This will load a question with 10 random numbers between 1 and 2000:

Code:
<script type="text/javascript" charset="utf-8">
  $(document).ready(function() {
 
    // Identify this question
    var qID = {QID};
    var thisQuestion = $('#question'+qID);
 
    // Build an array of 10 random numbers between 1 and 2000
    var numbers = [];
    while(numbers.length < 10){
      var randomnumber = Math.ceil(Math.random()*2000)
      if(numbers.indexOf(randomnumber) > -1) continue;
      numbers[numbers.length] = randomnumber;
    }
 
    // Load the question
    $(numbers).each(function(i, value) {
      $('input[type="text"]:eq('+i+')', thisQuestion).val(value);
    });
  });
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...6-07.lss
File Size:21 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.

Lime-years ahead

Online-surveys for every purse and purpose