Side by side: Randomize dropdown options | XM Community
Question

Side by side: Randomize dropdown options

  • 15 January 2021
  • 7 replies
  • 88 views

Userlevel 5
Badge +36

Is there a way to randomize the answer options in the dropdown list using custom code? In the randomization options within Qualtrics, I am only able to randomize the priority statements.
image.png


7 replies

Userlevel 3
Badge +8

On the rigjt side of the question, just under the Qnumber there is a cogwheel. If uou select that choose the option "Awnser randomization". This should randomize you anwser selection within the dropbox.
The values randomize within each of thw individual dropbox but the order is the same between the different dropboxes. What i am trying to say is that the values randomize for all dropdown randomize the same order between boxes.

Userlevel 7
Badge +27

dobra021 - Yes, you can write JS to shuffle the options in the drop down(s).
ruka - There isn't an option to randomize answers in a side-by-side question.

Userlevel 5
Badge +36

TomG - the JS that I think I need is something like this:
function randomArrayShuffle(array) {
  var currentIndex = array.length, temporaryValue, randomIndex;
  while (0 !== currentIndex) {
    randomIndex = Math.floor(Math.random() * currentIndex);
    currentIndex -= 1;
    temporaryValue = array[currentIndex];
    array[currentIndex] = array[randomIndex];
    array[randomIndex] = temporaryValue;
  }
  return array;
}
var options=["Option 1","Option 2","Option 3","Option 4","Option 5"];
randomArrayShuffle(options); 
});
Do I need to designate the questionId or some other selector for this to work?

Userlevel 7
Badge +27

https://www.qualtrics.com/community/discussion/comment/33522#Comment_33522Yes, so instead of a fixed array of options (option1, option2, etc.), you need to get the ids from the options in the select (i.e. dropdown) and add them to your "options" array. After you shuffle it, reorder the options by looping through the shuffled array where you find the option element for the current id and append it the bottom of select element.

Userlevel 3
Badge +8

https://www.qualtrics.com/community/discussion/comment/33467#Comment_33467TomG you are spot on. I did not look at the side-by-side detail!

Badge +1

Sorry to revive an old thread, but how did you implement this dobra021 and TomG ? I'm looking to do the same thing with a survey I'm putting together now and have never used javascript before.

Userlevel 7
Badge +27

https://community.qualtrics.com/XMcommunity/discussion/comment/51348#Comment_51348See: https://gist.github.com/marketinview/4d6916c1b180830ec97c04f03e59149b
Greatly simplified compared to dobra021's solution.

Leave a Reply