Auto Hide Options Based on Another Question Response | XM Community
Skip to main content

I have two multi answer questions in the same page. And what I’m trying to do is:

If Question 1 = code 1, Question 2 should show codes 1-5

if Question 1 = code 2, Question 2 should show codes 6-10

if Question 1 = code 3, Question 2 should show codes 11-15

Kindly note that Question 1 allows multiple answers. I have tried targetting the IDs of these options using javascript and CSS, but it’s still not hiding upon selection from Question 1. Having them shown in 2 different pages is not an option. Really hope you could help me here

Sharing here my source code:

It works in a sense, but the output isn’t looking good. The options are overlapping each other


Sharing here my source code:

It works in a sense, but the output isn’t looking good. The options are overlapping each other

@VyxlSantos You should put your code in text. It’s better for diagnosing


@Nam Nguyen apologies for that. Here you go:

    var Question2 = "QID5";

    

    this.questionclick = function(event,element) {

        

        var Question1 = this.getSelectedChoices();

        

        for (var i = 1; i <= 15; i++) {

            var Q2Option = document.getElementById("QR~" + Question2 + "~" + i.toString());

            var Q2OptionLabel = document.getElementById(Question2 + "-" + i.toString() + "-label");

            

            if ((Question1.includes("1") && i >= 1 && i <= 5) || (Question1.includes("2") && i >= 6 && i <= 10) || (Question1.includes("3") && i >= 11)) {

                //Q2Option.style.visibility = "visible";

                //Q2OptionLabel.style.visibility = "visible";

                Q2Option.style.display = "inline";

                //Q2OptionLabel.style.display = "inline";

            } else {

                //Q2Option.style.visibility = "hidden";

                //Q2OptionLabel.style.visibility = "hidden";

                Q2Option.style.display = "none";

                //Q2OptionLabel.style.display = "none";

            }

        }

        

    }


Leave a Reply