How to activate a text box to show up when a MC selection is made | XM Community
Skip to main content

Hello,
I am setting up a multiple choice question and would like a text box to appear only when a choice has been selected. Multiple selections can be made. Can someone provide me with a code for this?

Thanks!

isaibs there are several posts with solutions on here already. Here are a few to try:
https://community.qualtrics.com/XMcommunity/discussion/14020/how-can-i-display-a-text-box-to-a-question-if-someone-selects-otherThere is code within here for what you want to do, but pieces you should ignore
https://community.qualtrics.com/XMcommunity/discussion/23373/hiding-showing-text-entry-boxes-on-mc-prefix-and-suffix-issues


Hi @isaibs, this one works for me:

 

Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/

});

Qualtrics.SurveyEngine.addOnReady(function() {
var text_box = this.getChoiceContainer().querySelector(".TextEntryBox");
jQuery(text_box).hide();

this.questionclick = function() {
var text_choice = jQuery(text_box).parent().children(".q-checked").length > 0;
if (text_choice) {
jQuery(text_box).show();
} else {
jQuery(text_box).hide();
}
};
});


Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/

});

 


Hi @isaibs, this one works for me:

 

Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/

});

Qualtrics.SurveyEngine.addOnReady(function() {
var text_box = this.getChoiceContainer().querySelector(".TextEntryBox");
jQuery(text_box).hide();

this.questionclick = function() {
var text_choice = jQuery(text_box).parent().children(".q-checked").length > 0;
if (text_choice) {
jQuery(text_box).show();
} else {
jQuery(text_box).hide();
}
};
});


Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/

});

 

There are some issues with this code such as not accounting for multiple allow text fields and the possibility of hidden entered text causing validation errors.


Hi @TomG, I'm not sure why those two things should be necessary, but do you think that this one by @ahmedA resolves these issues?

Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/

});

Qualtrics.SurveyEngine.addOnReady(function () {
var text_box = this.getChoiceContainer().querySelector(".TextEntryBox");
text_box.hide();

this.questionclick = function () {
var text_choice = text_box.ancestors())1].childrenn1].className.includes("checked");
if (text_choice) {
text_box.show();
} else {
text_box.hide();
}
};
});


Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/

});

 


@JohannesCE - no it doesn’t.


Great


Leave a Reply