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

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. 🙂

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();
}
}
};
});


That's worked wonders. Thank you ahmedA


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)?


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].childrent1].className.includes("checked");
        if (text_choice) {
            text_box.show();
        } else {
            text_box.hide();
        }
    };
});


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


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.


Leave a Reply