Dynamic calculation from multiple sliders to a custom total | XM Community
Skip to main content

Hi all,

I am trying to make a custom constant sum question out of four questions: Q59, Q60, Q61, and Q62 (which are all comprised of one slider each, and I’ve hidden the title so it looks like one question). My Q63 is a slider that I’m trying to display the total of the former four sliders. I cannot do this with the built-in functionalities because the ranges of sliders in Q59-Q62 are all different. However, my JS code is not working, so when I try it in preview, Q63 slider does not update with the sum of the values of the prior 4 questions. Would be extremely grateful for any suggestions!

 

Qualtrics.SurveyEngine.addOnReady(function() {
   
  var quid_1 = 'QID59';
  var quid_2 = 'QID60';
  var quid_3 = 'QID61';
  var quid_4 = 'QID62';
  var quid_slider = 'QID63';


  function updateSlider() {
      var slider1 = parseInt(jQuery("#QID59 input.ResultsInput").eq(0).val());
      var slider2 = parseInt(jQuery("#QID60 input.ResultsInput").eq(0).val());
      var slider3 = parseInt(jQuery("#QID61 input.ResultsInput").eq(0).val());
      var slider4 = parseInt(jQuery("#QID62 input.ResultsInput").eq(0).val());
      
      var slidertotal = slider1 + slider2 + slider3 + slider4;

 

    // Update the slider value

      jQuery("#QID63 input.ResultsInput").eq(0).val(slidertotal);

  }

  // Add event listeners so that the slider updates when QID59, QID60, QID61, or QID62 change
  hquid_1, quid_2, quid_3, quid_4].forEach(function(quid) {
    jQuery("#" + quid + " inputttype='text']").on("input", updateSlider);
  });

  // call the function
  updateSlider();
});

 

Be the first to reply!

Leave a Reply