Help with calculations in a matrix table | XM Community
Skip to main content
Question

Help with calculations in a matrix table

  • October 17, 2023
  • 2 replies
  • 93 views

Forum|alt.badge.img+1

I am using Qualtrics to create an order form and was able to find a thread on calculations in a text entry matrix table using JS. Is there a way to add a totals line/statement to that or can I add another question and pull the totals from the previous question down to it to create like an “order review”? 

Here is the JS that I found that works to calculate price totals.

Paste the following code in the js(OnReady) of the matrix question

jQuery("#"+this.questionId+" td.c5 input[type='text']").attr("readonly",true);
var p=[15,15,15,15,7,7,7,7,20];
jQuery("input[type='text']").each(function()
{
jQuery(this).blur(function()
{
var id = jQuery(this).prop('id');
if(jQuery("[id='"+id+"']").parent().prop('className').split(" ")[0]=="c4")
{
var s=jQuery("[id='"+id+"']").val();
var i=jQuery("[id='"+id+"']").closest(".ChoiceRow").index();
var a=s*p[i] | 0;
jQuery("[id='"+id+"']").closest(".ChoiceRow").find("td.c5 input[type='text']").val(a);
}
});
});

2 replies

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 6084 replies
  • October 20, 2023

@tcwvu526 - You might be interested in the orderFormMatrix function.


Forum|alt.badge.img+1
  • Author
  • 2 replies
  • October 20, 2023

Thank you @TomG