Add rows to matrix question using Javascript | XM Community
Solved

Add rows to matrix question using Javascript

  • 26 September 2018
  • 3 replies
  • 62 views

Badge +2
I have a list of names that I'd like to ask the same question for, but for each person taking the survey this list of names will be different (i.e. some people will have n = 10, others might have n = 5 or n = 20). Is there a way to add n rows to my matrix question without hardcoding the number of rows? In other words, I want the number of rows in this question to be dynamic, according to how many names are in the list.

Thanks for the help!
icon

Best answer by TomG 26 September 2018, 18:52

View original

3 replies

Userlevel 7
Badge +33
You have to add all rows and have to add display logic on each row so only required rows will appear for particular group.
Badge +2
Thanks for the fast response @bansalpeeyush29!

This doesn't quite address the issue though. I neglected to mention that this list will contain different names for each person as well. So hardcoding the list of names into the matrix doesn't quite work. Maybe the full story will help to answer my question:

- I have a .json file that is updated on a remote server that contains the lists of names as people are added to different conditions.
- The addOnload function goes and fetches this data, parses, and subsets it to get the right list of names for the given person (i already have this working).
- so I want each person to answer a question for every other person in their condition at the time that they take survey.

The optimal solution in my mind is to be able to add rows to the matrix using javascript for however many people are in the final list for that given condition.
Userlevel 7
Badge +27
@JakeParelman,

Your matrix has to have the maximum number of possible rows. You can't add rows dynamically because Qualtrics won't know about them and won't record the answers on the back end.

You have two choices:
1. Include all the people and hide the ones you don't want a respondent to see with display logic or JavaScript. This may result in many data fields for the question, but will keep your data clean.
2. Include the maximum number of rows a respondent may see, and pipe the row labels from your input data. The issue with this is approach is the data fields will represent different people for different respondents so you will have to unwind the data.

Leave a Reply