Edit Equation in the Total Box for Constant Sums | XM Community
Skip to main content
Question

Edit Equation in the Total Box for Constant Sums

  • January 14, 2021
  • 4 replies
  • 54 views

JacquelineS

Hi all,
Is there any way to edit the equation of the total box in constant sum questions? For example, instead of the total box showing [X+Y], I'd like it to show [X-Y]. I know I could just have my respondents input a negative number for "Y", but they fill out this survey regularly and have always input a positive number for Y. Right now, I have it as a text entry matrix where the respondents have to manually input the total and it always ends up being a little off.
Thanks in advance!

4 replies

Forum|alt.badge.img+8
  • Level 2 ●●
  • February 10, 2021

Hello JacquelineS
This code should work
Qualtrics.SurveyEngine.addOnReady(function () {
    var $this = jQuery(this.questionContainer);
    var total, inputVal;
    jQuery(".QuestionBody .SumInput input", $this).on("input", function () {
        total = 0;
        jQuery(".QuestionBody .SumInput input", $this).each(function (i) {
            inputVal = jQuery(this).val();
            if (inputVal && inputVal.trim().length > 0 && !isNaN(inputVal)) {
                total = i === 0 ? parseFloat(inputVal) : (total - parseFloat(inputVal));
            }
        });
        jQuery(".QuestionBody .SumTotal input", $this).val(total);
    });
});


JacquelineS
  • Author
  • February 10, 2021

https://www.qualtrics.com/community/discussion/comment/34389#Comment_34389This looks amazing and works perfectly for constant sums! ChiragK do you know of a way to change this for matrix constant sums. I'd love to have 4 statements and 2 scale points with the total being scale point 1 minus scale point 2 for each statement.


Forum|alt.badge.img+8
  • Level 2 ●●
  • February 11, 2021

JacquelineS Can you send the link with this type of question?


MikeW
Level 5 ●●●●●
Forum|alt.badge.img+14
  • Level 5 ●●●●●
  • March 2, 2021

https://www.qualtrics.com/community/discussion/comment/34405#Comment_34405JacquelineS - did you get this to work for a Matrix question? Are you able to share the code?