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

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!

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);
    });
});


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.


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


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?


Leave a Reply