Record random number generated on a slider interface | XM Community
Skip to main content

I have a survey in which I show multiple sliders on a page, and the concrete value of each slider is randomly selected from the range of 10-200 (as in the screenshot below). Is there a way to record which random number is generated for each slider?
This task is asking people to move the sliders to the position indicated by this randomly generated number. So eventually, I want to be able to tell whether participants' slider response matches the number shown on the left. Thank you in advance for any insights!
Screen Shot 2023-02-15 at 1.37.31 PM.png

Hi chu_2024 ,
You can achieve the above task by following steps:
1.Create embedded variable named Slider1,Slider2 and Slider3 (as many sliders are there);
2.Write below code in JS API of Qualtrics:
Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/


});


Qualtrics.SurveyEngine.addOnReady(function()
{
// The following code selects all DOM elements with the class "LabelWrapper" and assigns them to the variable "text".
let text = document.querySelectorAll("span.LabelWrapper");


// The following lines of code set embedded data in a Qualtrics survey.
// The first line sets the value of the first element in the "text" array as the value for an embedded data field named "Slider1".
Qualtrics.SurveyEngine.setEmbeddedData('Slider1', text[0].innerText)
// The second line sets the value of the second element in the "text" array as the value for an embedded data field named "Slider2".
Qualtrics.SurveyEngine.setEmbeddedData('Slider2', text[1].innerText)
// The third line sets the value of the third element in the "text" array as the value for an embedded data field named "Slider3".
Qualtrics.SurveyEngine.setEmbeddedData('Slider3', text[2].innerText)

});


Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/


});
Hope it resolves your query😊!!!


Leave a Reply