How do I reference matrix question answer in JavaScript code? | XM Community
Solved

How do I reference matrix question answer in JavaScript code?

  • 27 July 2021
  • 2 replies
  • 201 views

I have a matrix question and if, e.g. the checkbox in the first row and first column is checked, I want to set an embedded element to that time. How can I implement this?
I have something like this in mind:
Pseude Code:
if (checkbox in first row/first column is checked) {
var timestamp = Date.now();
Qualtrics.SurveyEngine.setEmbeddedData('t1', timestamp);
}


icon

Best answer by cbhavsar 28 July 2021, 12:31

View original

2 replies

Userlevel 4
Badge +26

Hi,
I am assuming your matrix question is single choice and on same screen on which you are writing this script.
Here is how you can write the code inside addOnload function:
  this.questionclick = function(e,el)
  {
    if (el.type == 'radio')
    {
      var rowNum = el.id.split('~')[2];
      var colNum = el.id.split('~')[3];
      if (rowNum == 1 && colNum == 1) {
            var timestamp = Date.now();
            Qualtrics.SurveyEngine.setEmbeddedData('t1', timestamp);
            }
      }
}

All the best for your project!

https://community.qualtrics.com/XMcommunity/discussion/comment/39396#Comment_39396Thanks a lot! However, it's a multi choice answer but that should work pretty similar.

Leave a Reply