change "total" text on constant sum matrix table question | XM Community
Skip to main content

Hi

I'm trying to change the wording for the constant sum row of my matrix table using the addOnload function. I have the below, but it's now working. Any ideas as to what I'm doing wrong? I'm new to Javascript!
Qualtrics.SurveyEngine.addOnload(function()
{
jQuery("label[for="+this.questionId+"_Total]").html("Total like-for-like in-store income*(£)")

});


Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/


});


Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/


});
Thanks

Hi Berotti
The javascript provided by you does work and changes the label of total row as shown below.
Screenshot_2022-09-22-04-40-43-51_40deb401b9ffe8e1df2f1cc5ba480b12.jpgNot sure where you are facing issue. If you can provide additional information that would be great.
Hope this helps!


Hi @Deepak
Thanks for replying.
I've explored the issue a bit further. It looks like the above code works for Constant Sum questions, but not Matrix Table questions using the Matrix Table question type. See the below picture for how I have my question set up. Do you know how I could make the code work in this instance?
Matrix Table.PNG


Hello Berotti
You can use something like this for matrix-constant sum:
jQuery('[id="header~total~QID63"]').html("Total like-for-like in-store income*(£)");
//change the QID as needed//
and include this in HTML of question

Hope this helps!


Hi Deepak
That works when the 'Total' is a column, but not when it's a row. I've tried transposing the table and that doesn't help. Any idea how to fix this? Is it a case of switching out the word 'header' for something else?


Hello Berotti
You just have to switch words your JS would now be
jQuery('[id="header~QID63~total"]').html("Total like-for-like in-store income*(£)");

Hope this helps!


That didn't work.
I appreciate I'm not doing much to help myself here, sorry Deepak. I've done some googling but struggling to get my head around how Javascript operates. What does switching words in the string as you did above achieve? How does the ID function locate which text to replace?


In my case it did work, not sure where you are facing the issue. To find ID you can inspect the specific element and use it in Javascript.
I was able to achieve this as shown below:
image.pngUsed this in onload: jQuery('[id="header~QID65~total"]').html("Total like-for-like in-store income*(£)");
You need to change the QID in this JS if you are not already doing it.

Hope this helps!


It worked, I was being an idiot and using a QID from a different survey. Thanks Deepak for all your help!


It is best to avoid hard coding QID's in JS. Total can be updated like this:
jQuery("#"+this.questionId+" .CSTotal th.c1").html("Total like-for-like in-store income*(£)");


Leave a Reply