Extracting data from custom two-knob slider | XM Community
Question

Extracting data from custom two-knob slider

  • 6 March 2020
  • 1 reply
  • 5 views

I am trying to modify some custom code for a two-knob slider (found here) so that I can set embedded data from the 2 points that are selected with the knobs. I have 'Q1_min' and 'Q1_max" set as blank embedded data fields in my survey flow, but I can't get this code to write anything to those embedded data fields. I am very inexperienced with javascript, so any help (especially with explicit explanation) is much appreciated. Here is what I have so far:

Qualtrics.SurveyEngine.addOnload(function()
{
var surface;
var cnst = 1;
var min;
var max;
// Sets the sliders parameters and starting values
$("#research-slider").slider({ id: "research-slider", min: 0, max: 100, range: true, value: [0, 100]});
// variable to store in surface area when user has stopped sliding
var surface, currentResponse;
$("#research-slider").on("slideStop", function(slideEvt) {
surface = slideEvt.value;
document.getElementById("minimum").innerHTML = surface[0];
document.getElementById("maximum").innerHTML = surface[1];
document.getElementById("range").innerHTML = (surface[1]- surface[0])/cnst ;
min = surface[0];
max = surface[1];
});

Qualtrics.SurveyEngine.setEmbeddedData( 'Q1_min', min);
Qualtrics.SurveyEngine.setEmbeddedData( 'Q1_max', max);

$('NextButton').onclick = function (event) {
// and now run the event that the normal next button is supposed to do
Qualtrics.SurveyEngine.navClick(event, 'NextButton')
}



})

1 reply

Userlevel 7
Badge +22
Update the code as below:

Qualtrics.SurveyEngine.addOnload(function()
{
var surface;
var cnst = 1;
var min;
var max;
// Sets the sliders parameters and starting values
$("#research-slider").slider({ id: "research-slider", min: 0, max: 100, range: true, value: [0, 100]});
// variable to store in surface area when user has stopped sliding
var surface, currentResponse;
$("#research-slider").on("slideStop", function(slideEvt) {
surface = slideEvt.value;
document.getElementById("minimum").innerHTML = surface[0];
document.getElementById("maximum").innerHTML = surface[1];
document.getElementById("range").innerHTML = (surface[1]- surface[0])/cnst ;
min = surface[0];
max = surface[1];
Qualtrics.SurveyEngine.setEmbeddedData( 'Q1_min', min);
Qualtrics.SurveyEngine.setEmbeddedData( 'Q1_max', max);
});



$('NextButton').onclick = function (event) {
// and now run the event that the normal next button is supposed to do
Qualtrics.SurveyEngine.navClick(event, 'NextButton')
}

});

Leave a Reply