Dynamic accessing and recording slider values | XM Community
Skip to main content

I am trying to write code that starts with the slider question, and continuously records the value on the slider every second. To be more specific, my participants will be continuously rating their impressions of a character using the slider while listening to a story. I'm hoping to record their slider value every second and save this as comma separated values in an array.
I'm struggling to properly set up the embedded data saving and the setInterval, and I can't find examples of this anywhere else! Here is what I'm working with so far...

Please note: I am new to this so, if possible, please be specific about where in the code to implement any suggested code chunks or changes. Sincere thank you in advance.
Screen Shot 2021-10-28 at 12.09.54 PM.png

Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/
});
Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
var responses = [];
response_interval = setInterval(function(){
var response = parseInt(jQuery("#CRM1 input.ResultsInput").eq(0).val());
response += ", ";
responses.push(response);  
}, 1000)
});

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

Qualtrics.SurveyEngine.addOnPageSubmit(function(type)
{
if(type == "next"){
Qualtrics.SurveyEngine.setEmbeddedData("CRM-responses", responses);
}
});

Be the first to reply!

Leave a Reply