How can I display a text box to a question if someone selects "other" | XM Community
Skip to main content
Solved

How can I display a text box to a question if someone selects "other"

  • January 12, 2021
  • 7 replies
  • 2707 views

Amy_boz
Level 2 ●●
Forum|alt.badge.img+7

Hey everyone, I have a question I'm hoping someone can help
I have allowed a text box entry for a question with "other" as an option. This is for a multiple choice, single answer question. When I preview the question, the textbox appears under the whole list and I'd only like it to show if someone selects other. Is this possible?
Thanks for your help. :)

Best answer by ahmedA

This will work if the last option is the text entry box. See the demo here.
Qualtrics.SurveyEngine.addOnReady(function () {
text_box = this.getChoiceContainer().querySelector(".TextEntryBox");
text_box.hide();
n_choices = this.getChoices().length;

this.questionclick = function (event, element) {
if (element.type == "radio") {
if (element.id.split("~")[2] == n_choices) {
text_box.show();
} else {
text_box.hide();
}
}
};
});

7 replies

Forum|alt.badge.img+22
  • Level 7 ●●●●●●●
  • 2050 replies
  • Answer
  • January 12, 2021

This will work if the last option is the text entry box. See the demo here.
Qualtrics.SurveyEngine.addOnReady(function () {
text_box = this.getChoiceContainer().querySelector(".TextEntryBox");
text_box.hide();
n_choices = this.getChoices().length;

this.questionclick = function (event, element) {
if (element.type == "radio") {
if (element.id.split("~")[2] == n_choices) {
text_box.show();
} else {
text_box.hide();
}
}
};
});


Amy_boz
Level 2 ●●
Forum|alt.badge.img+7
  • Author
  • Level 2 ●●
  • 15 replies
  • January 12, 2021

That's worked wonders. Thank you ahmedA


Amy_boz
Level 2 ●●
Forum|alt.badge.img+7
  • Author
  • Level 2 ●●
  • 15 replies
  • February 1, 2021

Hi again! I have a quick question for the same java script - how do I change the code to display the box for multiple choice answers, instead of single choice (radio)?


Forum|alt.badge.img+22
  • Level 7 ●●●●●●●
  • 2050 replies
  • February 1, 2021

Here's the revised script that should work with almost all question types, Single select, multiple select, horizontal and vertical:
Qualtrics.SurveyEngine.addOnReady(function () {
    var text_box = this.getChoiceContainer().querySelector(".TextEntryBox");
    text_box.hide();

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


Amy_boz
Level 2 ●●
Forum|alt.badge.img+7
  • Author
  • Level 2 ●●
  • 15 replies
  • February 2, 2021

https://www.qualtrics.com/community/discussion/comment/33972#Comment_33972Once again, you've been an amazing help. Thank you ahmedA :)


Amy_boz
Level 2 ●●
Forum|alt.badge.img+7
  • Author
  • Level 2 ●●
  • 15 replies
  • May 9, 2022

https://community.qualtrics.com/XMcommunity/discussion/comment/33972#Comment_33972Is there a way to make this code work for a column alignment? I have 17 options I need to include and if I display the responses vertically that will take up too much screen space.


jamesbyrne
Level 1 ●
Forum|alt.badge.img+1
  • Level 1 ●
  • 4 replies
  • May 21, 2025

Thanks for this. Leaving a reply so I can find this again!