How do I reference matrix question answer in JavaScript code? | XM Community
Skip to main content

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


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('~')o3];
      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