Side by side: Randomize dropdown options | XM Community
Skip to main content
Question

Side by side: Randomize dropdown options

  • January 15, 2021
  • 7 replies
  • 150 views

dobra021
Level 4 ●●●●
Forum|alt.badge.img+37

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

ruka
QPN Level 2 ●●
Forum|alt.badge.img+12
  • QPN Level 2 ●●
  • January 15, 2021

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.


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • January 16, 2021

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.


dobra021
Level 4 ●●●●
Forum|alt.badge.img+37
  • Author
  • Level 4 ●●●●
  • January 19, 2021

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?


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • January 19, 2021

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.


ruka
QPN Level 2 ●●
Forum|alt.badge.img+12
  • QPN Level 2 ●●
  • January 28, 2021

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


Forum|alt.badge.img+1
  • October 26, 2022

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.


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • October 27, 2022