Grey out selection | Experience Community
Skip to main content
Solved

Grey out selection

  • July 7, 2026
  • 5 replies
  • 40 views

Forum|alt.badge.img+2

Hello, I have a multiple question but it has 2 parts, if the employee selects “N/A” is there a way to just grey out the 2nd part? I don’t wan’t to remove or proceed to next question, just want part 2 to be greyed out if N/A is chosen. Thanks

Best answer by vgayraud

Hi,

Test this out.

// PLACE THIS SCRIPT ON Q1 (the driver question). Legacy/Classic layout.
// Q2 (the other MC question on the same page) is greyed out and made
// non-interactable when ones of the NA choices is selected in Q1
// and its answer is cleared.
// QIDs are resolved dynamically.

Qualtrics.SurveyEngine.addOnReady(function () {
// CONFIG
var NA_RECODE_VALUES = ['3']; // recode value(s) of the NA option(s) in Q1
var DISABLED_OPACITY = '0.4';

var self = this;
var qid1 = this.questionId;

// RESOLVE Q2 — the other question on the page
var qid2 = null;
var allInfo = Qualtrics.SurveyEngine.QuestionInfo || {};
var ids = Object.keys(allInfo);
for (var i = 0; i < ids.length; i++) {
if (ids[i] !== qid1) { qid2 = ids[i]; break; }
}
if (!qid2) { return; }

var q1Container = this.getQuestionContainer();
if (!q1Container) { return; }

// RESOLVE NA CHOICE IDS FROM RECODE VALUES
var naIds = [];
for (var j = 0; j < NA_RECODE_VALUES.length; j++) {
var matches = this.getChoicesFromRecodeValue(NA_RECODE_VALUES[j]) || [];
for (var r = 0; r < matches.length; r++) { naIds.push(String(matches[r])); }
}
if (naIds.length === 0) { return; }
console.log('[naDisable] qid1=', qid1, 'qid2=', qid2, 'naIds=', naIds);

var naActive = false;

// LIVE Q2 CONTAINER
function getQ2Container() {
return document.getElementById('question-' + qid2) || document.getElementById(qid2);
}

// APPLY DISABLED STATE TO Q2
function applyState(container, disabled) {
if (!container) { return; }
container.style.opacity = disabled ? DISABLED_OPACITY : '';
container.style.pointerEvents = disabled ? 'none' : '';
if ('inert' in container) { container.inert = disabled; }
var fields = container.querySelectorAll('input, textarea, select, button');
for (var k = 0; k < fields.length; k++) { fields[k].disabled = disabled; }
}

// EVALUATE Q1 AND SET Q2
function updateState() {
var selected = self.getSelectedChoices() || [];
var isNA = false;
for (var n = 0; n < selected.length; n++) {
if (naIds.indexOf(String(selected[n])) !== -1) { isNA = true; break; }
}
naActive = isNA;
console.log('[naDisable] updateState Q1 selected:', selected, 'isNA=', isNA);

var container = getQ2Container();
applyState(container, isNA);

if (isNA) {
var q2 = Qualtrics.SurveyEngine.QuestionData.getInstance(qid2);
if (q2) {
var sel = q2.getSelectedChoices() || [];
console.log('[naDisable] Q2 selected before clear:', sel);
for (var c = 0; c < sel.length; c++) { q2.setChoiceValue(sel[c], false); }
console.log('[naDisable] Q2 selected after clear:', q2.getSelectedChoices());
}
}
}

// BIND Q1 CHANGES
var q1Inputs = q1Container.querySelectorAll('input');
for (var m = 0; m < q1Inputs.length; m++) {
q1Inputs[m].addEventListener('change', updateState);
}

// RE-APPLY ON Q2 RE-RENDER
var scope = document.getElementById('survey-canvas') || document.body;
var obs = new MutationObserver(function () {
if (!naActive) { return; }
applyState(getQ2Container(), true);
});
obs.observe(scope, { childList: true, subtree: true });
window['__naObs_' + qid1] = obs;

updateState();
});

Qualtrics.SurveyEngine.addOnPageSubmit(function () {
var obs = window['__naObs_' + this.questionId];
if (obs) { obs.disconnect(); window['__naObs_' + this.questionId] = null; }
});

 

5 replies

Forum|alt.badge.img+21
  • QPN Level 5 ●●●●●
  • July 7, 2026

hey ​@jduncan , can you please share a screenshot of the setup you have created. it will be helpful to work on a solution accordingly.


Forum|alt.badge.img+2
  • Author
  • Level 2 ●●
  • July 7, 2026

Sure thing! Below is a screenshot of what is currently on my survey, one question but 2 parts to the question. The employee must rate on role proficiency & role relevance. But if the skill does not apply to their work, they would choose N/A under proficiency but I need role relevenace to still appear just be greyed out.

 

 

 


Umang Upadhyay
QPN Level 4 ●●●●
Forum|alt.badge.img+31
  • QPN Level 4 ●●●●
  • July 9, 2026

Hi ​@jduncan I'm sure you may have already checked this, just wanted to save you some time. As far as I know, there isn't a native way to grey out just the Role Relevance field when N/A is selected. This can be achieved using custom JavaScript if that's an option for your survey.


vgayraud
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+65
  • QPN Level 8 ●●●●●●●●
  • Answer
  • July 9, 2026

Hi,

Test this out.

// PLACE THIS SCRIPT ON Q1 (the driver question). Legacy/Classic layout.
// Q2 (the other MC question on the same page) is greyed out and made
// non-interactable when ones of the NA choices is selected in Q1
// and its answer is cleared.
// QIDs are resolved dynamically.

Qualtrics.SurveyEngine.addOnReady(function () {
// CONFIG
var NA_RECODE_VALUES = ['3']; // recode value(s) of the NA option(s) in Q1
var DISABLED_OPACITY = '0.4';

var self = this;
var qid1 = this.questionId;

// RESOLVE Q2 — the other question on the page
var qid2 = null;
var allInfo = Qualtrics.SurveyEngine.QuestionInfo || {};
var ids = Object.keys(allInfo);
for (var i = 0; i < ids.length; i++) {
if (ids[i] !== qid1) { qid2 = ids[i]; break; }
}
if (!qid2) { return; }

var q1Container = this.getQuestionContainer();
if (!q1Container) { return; }

// RESOLVE NA CHOICE IDS FROM RECODE VALUES
var naIds = [];
for (var j = 0; j < NA_RECODE_VALUES.length; j++) {
var matches = this.getChoicesFromRecodeValue(NA_RECODE_VALUES[j]) || [];
for (var r = 0; r < matches.length; r++) { naIds.push(String(matches[r])); }
}
if (naIds.length === 0) { return; }
console.log('[naDisable] qid1=', qid1, 'qid2=', qid2, 'naIds=', naIds);

var naActive = false;

// LIVE Q2 CONTAINER
function getQ2Container() {
return document.getElementById('question-' + qid2) || document.getElementById(qid2);
}

// APPLY DISABLED STATE TO Q2
function applyState(container, disabled) {
if (!container) { return; }
container.style.opacity = disabled ? DISABLED_OPACITY : '';
container.style.pointerEvents = disabled ? 'none' : '';
if ('inert' in container) { container.inert = disabled; }
var fields = container.querySelectorAll('input, textarea, select, button');
for (var k = 0; k < fields.length; k++) { fields[k].disabled = disabled; }
}

// EVALUATE Q1 AND SET Q2
function updateState() {
var selected = self.getSelectedChoices() || [];
var isNA = false;
for (var n = 0; n < selected.length; n++) {
if (naIds.indexOf(String(selected[n])) !== -1) { isNA = true; break; }
}
naActive = isNA;
console.log('[naDisable] updateState Q1 selected:', selected, 'isNA=', isNA);

var container = getQ2Container();
applyState(container, isNA);

if (isNA) {
var q2 = Qualtrics.SurveyEngine.QuestionData.getInstance(qid2);
if (q2) {
var sel = q2.getSelectedChoices() || [];
console.log('[naDisable] Q2 selected before clear:', sel);
for (var c = 0; c < sel.length; c++) { q2.setChoiceValue(sel[c], false); }
console.log('[naDisable] Q2 selected after clear:', q2.getSelectedChoices());
}
}
}

// BIND Q1 CHANGES
var q1Inputs = q1Container.querySelectorAll('input');
for (var m = 0; m < q1Inputs.length; m++) {
q1Inputs[m].addEventListener('change', updateState);
}

// RE-APPLY ON Q2 RE-RENDER
var scope = document.getElementById('survey-canvas') || document.body;
var obs = new MutationObserver(function () {
if (!naActive) { return; }
applyState(getQ2Container(), true);
});
obs.observe(scope, { childList: true, subtree: true });
window['__naObs_' + qid1] = obs;

updateState();
});

Qualtrics.SurveyEngine.addOnPageSubmit(function () {
var obs = window['__naObs_' + this.questionId];
if (obs) { obs.disconnect(); window['__naObs_' + this.questionId] = null; }
});

 


Forum|alt.badge.img+2
  • Author
  • Level 2 ●●
  • July 10, 2026

Thank you so much!