Hiding scale points in a drop-down randomized matrix table | XM Community
Skip to main content

I have seen solutions for a regular matrix table. How do you do this on a drop down matrix table?

This screenshot shows how the question is set up. For gym membership, I would like to hide ‘daily’ and ‘weekly’.

 


Hi,

You can try this function.

Qualtrics.SurveyEngine.addOnReady(function () {
var that = this;

function hideDropdownItems(itemsToHide) {

// Detect layout and select appropriate dropdown structure
var questionRoot = document.querySelector('#question-' + that.questionId)
|| document.querySelector('#' + that.questionId);

if (!questionRoot) return;

var dropdownItems = questionRoot.querySelectorAll('li.menu-item');

var isCustomStructure = dropdownItems.length > 0;
if (!isCustomStructure) {
dropdownItems = questionRoot.querySelectorAll('select');
}

// New Survey Taking Experience with dropdowns using <li.menu-item>
if (isCustomStructure) {
for (var i = 0; i < dropdownItems.length; i++) {
var item = dropdownItems[i];
var id = item.id;

if (!id || !id.startsWith('menu-item-')) continue;

var parts = id.split('-'); // "menu-item-1-2"
if (parts.length < 4) continue;

var statementNum = parts[2];
var scaleNum = parts[3];

for (var j = 0; j < itemsToHide.length; j++) {
var rule = itemsToHide[j];
if (rule[0] === statementNum && rule[1] === scaleNum) {
item.style.display = 'none';
break;
}
}
}
}

// Legacy layouts with <select> structure
else {
for (var i = 0; i < dropdownItems.length; i++) {
var select = dropdownItems[i];
var selectId = select.id; // e.g., QR~QID1~2
var idParts = selectId.split('~');
if (idParts.length < 3) continue;

var statementNum = idParts[2];

var options = select.querySelectorAll('option');
for (var j = 0; j < options.length; j++) {
var option = options[j];
var scaleNum = option.value;
if (!scaleNum) continue;

for (var k = 0; k < itemsToHide.length; k++) {
var rule = itemsToHide[k];
if (rule[0] === statementNum && rule[1] === scaleNum) {
option.hidden = true;
break;
}
}
}
}
}
}

// [statementNum, scalePointNum] you want to hide
var itemsToHide = [
["1", "2"],
["2", "3"],
["3", "1"]
];

hideDropdownItems(itemsToHide);
});

 


It worked. Thanks!