retrieve matrix table selected values using javascript? | XM Community
Question

retrieve matrix table selected values using javascript?

  • 3 July 2021
  • 9 replies
  • 314 views

Hello everyone,
I want to make a custom calculation on the values of a matrix table of 10 rows. To do so I was trying to retrieve the individual values of each row using
var r1ar = parseInt("${q://QID81/SelectedAnswerRecode/1}");
var r2ar = parseInt("${q://QID81/SelectedAnswerRecode/2}");
var r3ar = parseInt("${q://QID81/SelectedAnswerRecode/3}");
...
statements. The above code is not working. I used the alert statement to retrieve the selection value
alert("${q://QID81/SelectedAnswerRecode/1}")
and got an empty alert window.
I have added the code on Qualtrics.SurveyEngine.addOnPageSubmit function. Can you please guide me how I can reach the individual values of a matrix table?
Thank you,



9 replies

Userlevel 7
Badge +21

You need to have a page break between storing values and using the Qualtrics Piped text format.

Thank you ahmedA! it worked. Is there any other way without adding any page break? If it needs additional javascript (adding an event to the matrix table) I am also fine with that one.
Thank you!

Userlevel 7
Badge +21

You can add an event listener to next button and pull the values from the matrix.

thanks ahmedA!
On the same question without adding any page breaks, I have added the following code within the Qualtrics.SurveyEngine.addOnReady and Qualtrics.SurveyEngine.addOnPageSubmit functions
$('NextButton').onclick = function (event) {
alert("${q://QID81/SelectedAnswerRecode/1}")
alert("${q://QID81/SelectedAnswerRecode/2}")
};
and got an empty alert window. Can you please suggest if my code is correct and provide a direction? Thank you!

Userlevel 7
Badge +21

"${q://QID81/SelectedAnswerRecode/1}" These values come from the server. Hence will ONLY be available in the next page.
Pick the value from the matrix itself, the input box or whatever you have.
Read up on the Qualtrics JavaScript API, this will give you an idea of what all information you can gather.
If you're facing issues in a particular case, share the preview link, along with what you are looking for and maybe I'll be able to provide more directed help.

thanks ahmedA,
I can retrieve the values from input boxes, multiple choice or forms on the page. However, for the matrix table I don't know how to retrieve the values without asking the server. I have searched on the the internet and couldn't find it. If you can share a resource that enables me to get the values of a matrix table on the page using jquery or any other form of javascript that would be great!
There is nothing special: on the page I need to retrieve the selected values from the matrix table to calculate an embedded field.
Thank you for your help.

Userlevel 7
Badge +21

If you're facing issues in a particular case, share the preview link, along with what you are looking for and maybe I'll be able to provide more directed help.

thank you ahmedA. since this is a university project I need to get approval from the committees before sharing anything even if it is a preview. thank you for your help.

Userlevel 7
Badge +21

Okay. Take your time. However, generally for confidential things, people just put dummy text and share it. But it's your call.

Leave a Reply