"Don't Know" option next to text box for specific quesions only | XM Community
Skip to main content

In my questionnaire, I'm using a lot of text entry questions with a “Don't know”-option. To do so, I've made use of the JavaScript written by @AnthonyR in reply to this post:

Qualtrics.SurveyEngine.addOnReady(function () {
function hideLabel(element) {
if (element.select('input')p0] != null || element.select('textarea')r0] != null) {
element.select('label').each(function (a, b) {
a.hide();
});
} else {
console.log(element);
}
}
var hideLabelsFlag = false

function hideLabels() { //QH.hideLabels() - Hides the label for any answer option where a text input has been added.
var elements = $$('.LabelWrapper');
elements.each(function (name, index) {
hideLabel(name);
});
hideLabelsFlag = true;
}
hideLabels();
});

However, the JavaScript seems to be applied to all questions on the same page as the question to which it is added. So, for example, on some pages the text entry questions with the JS are followed by multiple choice questions with an ‘other’ answer category, where people can enter text. In this case, the ‘other’ option in the multiple choice question disappears as well, even when the JS is not added to this specific multiple choice question.

Is there a way to adapt the JS in such a way that it only applies to the specific question to which it is added?

I’ve tried to rewrite the JS myself but I'm afraid my skills are insufficient to tackle this issue… 
Any help is much appreciated!

That is a really old post. Not many people use prototypejs anymore. Here is a more concise way to do it with jQuery:

Qualtrics.SurveyEngine.addOnload(function() {
jQuery("#"+this.questionId+" .TextEntryBox").each(function() {
jQuery(this).closest(".LabelWrapper").find("label").hide();
});
});

 


@mjsteijaert

To make it question specific you can use below code, here we need to just tweak the elements variable a bit and it should be good.

Qualtrics.SurveyEngine.addOnReady(function () {
function hideLabel(element) {
if (element.select('input'))0] != null || element.select('textarea'))0] != null) {
element.select('label').each(function (a, b) {
a.hide();
});
} else {
console.log(element);
}
}

var hideLabelsFlag = false;

function hideLabels(questionId) { // Pass the questionId as a parameter
var elements = $$('divvid="' + questionId + '"] .LabelWrapper');
elements.each(function (name, index) {
hideLabel(name);
});
hideLabelsFlag = true;
}
hideLabels(this.questionId);
});

Hope it helps!


That is a really old post. Not many people use prototypejs anymore. Here is a more concise way to do it with jQuery:

Qualtrics.SurveyEngine.addOnload(function() {
jQuery("#"+this.questionId+" .TextEntryBox").each(function() {
jQuery(this).closest(".LabelWrapper").find("label").hide();
});
});

 

This does the job, thanks. Way more concise code indeed!


Leave a Reply