Randomize order of two audio files within a question | XM Community
Skip to main content

Hi!
I want to present a question with text followed by two audio files. However, I would like the order of the two audios to be presented randomly. Does anyone know how I could use code to achieve this?
Thank you very much!

There are multiple ways to achieve this: One of the way is to create those audio files questions in separate and in it's own separate block then use Randomization element from the survey flow.


Hi Shashi,
Thank you for your reply! I thought of using this solution, but I was hoping someone would know how to do this with code instead. I have several questions where I need to randomize the audio within the same question in the same survey, so I was hoping I would be able to avoid building one block per question by using code. But this is definitely a good option if I cannot make it work with code. Thanks!


Hi mfcl,
This can be done using Display logic and Randomizer! I am attaching screenshots below for your reference.

  • Survey Builder

  • image.pngSurvey Flow

image.png
Hope this helps!


Hi TusharDalwani,
Thank you for your reply! I was not aware of this function. However, it seems like I would still have to use multiple questions, is that correct? What I would like to do is to have both audio files within the same question. But if it is not possible to use code to achieve this, what you suggests seems to be a good option. Thanks!


mfcl ,
Put your audio tags in divs with the same class, like this:







Then use this JS:
Qualtrics.SurveyEngine.addOnload(function() {
var audios = jQuery("#"+this.questionId+" .audio");
if(Math.random() > 0.5) audios.last().after(audios.first());
});


https://community.qualtrics.com/XMcommunity/discussion/comment/46720#Comment_46720Thank you TomG! This is exactly what I was trying to do! 🙂 I tried the code and it works perfectly.


Leave a Reply