Matrix question selections as piped text | XM Community
Skip to main content

I have a matrix question that allows multiple answers. I was wondering whether it is possible to populate each selection into follow-up questions.

For example, in the matrix I have rows (A, B, C, etc.) and columns (1, 2, 3, etc.). If a respondent selects A1, A2, and B3, the follow-up questions will ask opinions on A1, A2, and B3 (i.e., agree or disagree with them)

The following approaches do not work for me:

(1) adding branches is not feasible because the matrix question produces hundreds of possible combinations.

(2) I was able to add all selected choices (selected rows in the matrix) or all selected answers (selected columns) as piped text but not their combinations (cells).

(3) Similarly,  loop & merge does not work since it allows only looping over selected rows or columns. And adding piped text in additional fields is not helpful because selected choices or selected answers come in groups and individual choice/answer cannot be separated out. 

(4) I have tried using JavaScript to modify the follow-up questions. I can sometimes modify the question stem successfully but had not luck in modifying the response options. 

(5) Carrying forward choices is an alternative but less efficient. 

 

I have found a similar post here but no solutions are provide.

 

I also contacted Qualtrics Support and they replied “Qualtrics Support is not trained on custom coding” and suggested posting here. 

 

These attempts make me wonder whether there is an identifier for each cell in the matrix question that we can use as piped text. 

Any other suggestions will be appreciated! 

Hi gracewu42,

 

I don't think there is an easy way to do this but you can achieve this with bit of trick and using excel to create labels for follow up questions:

 

Step 1 -  Carry forward your scale 1 selected options, recode statement values as 1,2,3,4...if it's not already there. Copy this code in javascript

Qualtrics.SurveyEngine.addOnReady(function()
{
    /*Place your JavaScript here to run when the page is fully displayed*/
jQuery("#"+this.questionId).hide();


    jQuery("#"+this.questionId+" echoiceid]").prop("checked",true);
     var qobj = this;
    qobj.clickNextButton();


});

Step 2 - Copy the question above, change carry forward from scale 2. Repeat until you do this for the number of scales you have e.g if it's 5 create 5 such/hidden questions.

Step 3 - Final hidden question - Via excel create combinations for all statements e.g A1,A2,A3,B1,B2,B3 and apply recode values as 11,12,13 then 21,22,23, 31,32,33… and so on.

 

Finally put this script in your javascript tab

 

Qualtrics.SurveyEngine.addOnReady(function()
{

jQuery("#"+this.questionId).hide();
arrC1="${q://QID12/SelectedChoicesRecode}";  /*Updated qualtrics id of first hidden question*/
arrC2="${q://QID13/SelectedChoicesRecode}"; /*Updated qualtrics id of second hidden question*/
    /*Add additional array here depending on # of scales you have*/
    for(var i=0;i<arrC1.length;i++)  /*Duplicate this loop for # of arrays/hidden question you may have*/
    {
    var choiceVal="";
    choiceVal=arrC1oi]+1;    //change arr name for each loop
        //alert(choiceVal);
         
                      this.setChoiceValueByRecodeValue(choiceVal, true);
                    
               
    
    }
        for(var i=0;i<arrC2.length;i++)
    {
    var choiceVal="";
    choiceVal=arrC2(i]+2;    
        //alert(choiceVal);
         
                      this.setChoiceValueByRecodeValue(choiceVal, true);
                    
               
    
    }

   
     var qobj = this;
    qobj.clickNextButton();

});

 

You can then use the final question in your loop and merge or anywhere just by carry forwarding the displayed items(suggested) but carry forward from selected will also work.

 

Please note you will see bit of loading between starting matrix to piping question, though it will take only 1-2 seconds but you can add some instructions e.g you will see some loading for a while, please be patient. 


Hi gracewu42,

 

I don't think there is an easy way to do this but you can achieve this with bit of trick and using excel to create labels for follow up questions:

 

Step 1 -  Carry forward your scale 1 selected options, recode statement values as 1,2,3,4...if it's not already there. Copy this code in javascript

Qualtrics.SurveyEngine.addOnReady(function()
{
    /*Place your JavaScript here to run when the page is fully displayed*/
jQuery("#"+this.questionId).hide();


    jQuery("#"+this.questionId+" echoiceid]").prop("checked",true);
     var qobj = this;
    qobj.clickNextButton();


});

Step 2 - Copy the question above, change carry forward from scale 2. Repeat until you do this for the number of scales you have e.g if it's 5 create 5 such/hidden questions.

Step 3 - Final hidden question - Via excel create combinations for all statements e.g A1,A2,A3,B1,B2,B3 and apply recode values as 11,12,13 then 21,22,23, 31,32,33… and so on.

 

Finally put this script in your javascript tab

 

Qualtrics.SurveyEngine.addOnReady(function()
{

jQuery("#"+this.questionId).hide();
arrC1="${q://QID12/SelectedChoicesRecode}";  /*Updated qualtrics id of first hidden question*/
arrC2="${q://QID13/SelectedChoicesRecode}"; /*Updated qualtrics id of second hidden question*/
    /*Add additional array here depending on # of scales you have*/
    for(var i=0;i<arrC1.length;i++)  /*Duplicate this loop for # of arrays/hidden question you may have*/
    {
    var choiceVal="";
    choiceVal=arrC1ii]+1;    //change arr name for each loop
        //alert(choiceVal);
         
                      this.setChoiceValueByRecodeValue(choiceVal, true);
                    
               
    
    }
        for(var i=0;i<arrC2.length;i++)
    {
    var choiceVal="";
    choiceVal=arrC2ri]+2;    
        //alert(choiceVal);
         
                      this.setChoiceValueByRecodeValue(choiceVal, true);
                    
               
    
    }

   
     var qobj = this;
    qobj.clickNextButton();

});

 

You can then use the final question in your loop and merge or anywhere just by carry forwarding the displayed items(suggested) but carry forward from selected will also work.

 

Please note you will see bit of loading between starting matrix to piping question, though it will take only 1-2 seconds but you can add some instructions e.g you will see some loading for a while, please be patient. 

Hi @faaiz.rahman! Thanks for your reply! 

The logic of these steps makes sense to me. But they did not work on my end and I am suspecting it is about the recode values. For some reason even though I have set the recode values as 1, 2, 3, 4, 5 in the hidden questions, it is sometimes displayed as x1, x2, x3, x4, x5 (sometimes it is 1, 2, 3, 4, 5 but the loop & merge is still not working) when I display ${q://QID30/SelectedChoicesRecode}. 

Any further suggestions? 

 

 


Hi,

I had a similar need a while ago and I chose to use a styled MCMA question instead of a matrix. I was using the classic layout but you can achieve the same results in another layout with some adjustments.

Use a MCMA question with a column alignment:

 

Add this custom javascript code:

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

// display checkboxes in classic layout
var checkboxLabels = document.querySelectorAll('#' + this.questionId + ' label.q-checkbox');
checkboxLabels.forEach(function(label) {
label.style.display = 'block';
});

// hide labels in classic layout
var labelContainers = document.querySelectorAll('#' + this.questionId + ' td.LabelContainer');
labelContainers.forEach(function(td) {
td.style.display = 'none';
});

// add row and column statements
var table = document.querySelector('#' + this.questionId + ' .ChoiceStructure');

var newRow = table.insertRow(0);
newRow.insertCell(0).textContent = 'Column 1\'s statement';
newRow.insertCell(1).textContent = 'Column 2\'s statement';
newRow.insertCell(2).textContent = 'Column 3\'s statement';

newRow.style.textAlign = 'center'; // Center aligns all cells in the newRow

var rows = table.rows;
for (var i = 0; i < rows.length; i++) {
var cell = rowssi].insertCell(0);
if (i === 0) {
cell.textContent = '';
} else {
if (i === 1) {
cell.textContent = 'Row A\'s statement';
} else if (i === 2) {
cell.textContent = 'Row B\'s statement';
} else if (i === 3) {
cell.textContent = 'Row C\'s statement';
}
}
}

// select all td elements containing input and label elements
var tdInputsLabels = document.querySelectorAll('#' + this.questionId + ' td input, #' + this.questionId + ' td label');
// loop through each td element containing input or label
tdInputsLabels.forEach(function(elem) {
var td = elem.closest('td');
td.style.textAlign = 'center'; // center align the content within the td element
elem.style.margin = 'auto'; // style the input and label elements for centering
elem.style.display = 'block';
});

});

The result will look like this:

Since your answers are not split between multiple variables like they are in a matrix, you can use whatever logic or loop & merge you want after.


@vgayraud  Thanks for replying! This is a good workaround and I believe it will be useful for some people. 

Might not be applicable in my case since my matrix question is a dynamic one that carries forward statements/scales from previous selections. 


Hi gracewu42,

 

I don't think there is an easy way to do this but you can achieve this with bit of trick and using excel to create labels for follow up questions:

 

Step 1 -  Carry forward your scale 1 selected options, recode statement values as 1,2,3,4...if it's not already there. Copy this code in javascript

Qualtrics.SurveyEngine.addOnReady(function()
{
    /*Place your JavaScript here to run when the page is fully displayed*/
jQuery("#"+this.questionId).hide();


    jQuery("#"+this.questionId+" echoiceid]").prop("checked",true);
     var qobj = this;
    qobj.clickNextButton();


});

Step 2 - Copy the question above, change carry forward from scale 2. Repeat until you do this for the number of scales you have e.g if it's 5 create 5 such/hidden questions.

Step 3 - Final hidden question - Via excel create combinations for all statements e.g A1,A2,A3,B1,B2,B3 and apply recode values as 11,12,13 then 21,22,23, 31,32,33… and so on.

 

Finally put this script in your javascript tab

 

Qualtrics.SurveyEngine.addOnReady(function()
{

jQuery("#"+this.questionId).hide();
arrC1="${q://QID12/SelectedChoicesRecode}";  /*Updated qualtrics id of first hidden question*/
arrC2="${q://QID13/SelectedChoicesRecode}"; /*Updated qualtrics id of second hidden question*/
    /*Add additional array here depending on # of scales you have*/
    for(var i=0;i<arrC1.length;i++)  /*Duplicate this loop for # of arrays/hidden question you may have*/
    {
    var choiceVal="";
    choiceVal=arrC1ci]+1;    //change arr name for each loop
        //alert(choiceVal);
         
                      this.setChoiceValueByRecodeValue(choiceVal, true);
                    
               
    
    }
        for(var i=0;i<arrC2.length;i++)
    {
    var choiceVal="";
    choiceVal=arrC2=i]+2;    
        //alert(choiceVal);
         
                      this.setChoiceValueByRecodeValue(choiceVal, true);
                    
               
    
    }

   
     var qobj = this;
    qobj.clickNextButton();

});

 

You can then use the final question in your loop and merge or anywhere just by carry forwarding the displayed items(suggested) but carry forward from selected will also work.

 

Please note you will see bit of loading between starting matrix to piping question, though it will take only 1-2 seconds but you can add some instructions e.g you will see some loading for a while, please be patient. 

Hi @faaiz.rahman! Thanks for your reply! 

The logic of these steps makes sense to me. But they did not work on my end and I am suspecting it is about the recode values. For some reason even though I have set the recode values as 1, 2, 3, 4, 5 in the hidden questions, it is sometimes displayed as x1, x2, x3, x4, x5 (sometimes it is 1, 2, 3, 4, 5 but the loop & merge is still not working) when I display ${q://QID30/SelectedChoicesRecode}. 

Any further suggestions? 

 

 

I figured out the problem with the leading x. I have to recode the response options in the very first question that I use to carry forward choices to avoid the leading x. After fixing that, it worked smoothly! 


Leave a Reply