Having Response to One Question Auto-populate the response to another on the same page? | XM Community
Solved

Having Response to One Question Auto-populate the response to another on the same page?

  • 24 April 2024
  • 3 replies
  • 87 views

Badge +1

I have three multiple choice questions on one page.

1) I Accept Condition A (accept/reject)

2) I Accept Condition B (accept/reject)

3) Accept all / reject all

What I want is when someone clicks Accept All on (3), for "Accept" to become automatically selected on (1) and (2) (with the opposite being true when Reject All is selected on (3)). From a UX perspective, it would be helpful if pressing a selection on (3) visibly changed the answers to (1) and (2), e.g. the bubbles next to them becomes selected.

 

Does anyone have any tips on how to do this?

icon

Best answer by RickB 25 April 2024, 10:57

View original

3 replies

Userlevel 1
Badge +6

Hi @spurl 

 

you can use this code:

Qualtrics.SurveyEngine.addOnload(function() {

    // Function to handle click event on "Accept All" button

    var acceptAllButton = document.getElementById("QR~QID_of_question_3~1");

    acceptAllButton.onclick = function() {

        // Select "Accept" option for questions 1 and 2

        document.getElementById("QR~QID_of_question_1~1").click();

        document.getElementById("QR~QID_of_question_2~1").click();

    };

    // Function to handle click event on "Reject All" button

    var rejectAllButton = document.getElementById("QR~QID_of_question_3~2");

    rejectAllButton.onclick = function() {

        // Select "Reject" option for questions 1 and 2

        document.getElementById("QR~QID_of_question_1~2").click();

        document.getElementById("QR~QID_of_question_2~2").click();

    };

});

 

Replace "QR~QID_of_question_3~1" and "QR~QID_of_question_3~2" with the actual question IDs for the "Accept All" and "Reject All" buttons respectively. Similarly, replace "QR~QID_of_question_1~1" and "QR~QID_of_question_1~2" with the actual question IDs for the "Accept" and "Reject" options of question 1, and do the same for question 2.

This code will automatically select the appropriate options for questions 1 and 2 when the "Accept All" or "Reject All" button is clicked, and the changes will be reflected visually in the survey interface.

Badge +1

Thank you, this is super helpful! As an add-on, I'm trying to have any additional clicks on questions 1 and 2 to automatically unclick the accept all and reject all buttons. I already coded the accept all / reject all to be multiple answer with exclusive options (meaning you can deselect an option by clicking). Any suggestions for this?

Hi @spurl 

 

you can use this code:

Qualtrics.SurveyEngine.addOnload(function() {     // Function to handle click event on "Accept All" button     var acceptAllButton = document.getElementById("QR~QID_of_question_3~1");     acceptAllButton.onclick = function() {         // Select "Accept" option for questions 1 and 2         document.getElementById("QR~QID_of_question_1~1").click();         document.getElementById("QR~QID_of_question_2~1").click();     };

    // Function to handle click event on "Reject All" button     var rejectAllButton = document.getElementById("QR~QID_of_question_3~2");     rejectAllButton.onclick = function() {         // Select "Reject" option for questions 1 and 2         document.getElementById("QR~QID_of_question_1~2").click();         document.getElementById("QR~QID_of_question_2~2").click();     }; });
 

Replace "QR~QID_of_question_3~1" and "QR~QID_of_question_3~2" with the actual question IDs for the "Accept All" and "Reject All" buttons respectively. Similarly, replace "QR~QID_of_question_1~1" and "QR~QID_of_question_1~2" with the actual question IDs for the "Accept" and "Reject" options of question 1, and do the same for question 2.

This code will automatically select the appropriate options for questions 1 and 2 when the "Accept All" or "Reject All" button is clicked, and the changes will be reflected visually in the survey interface.

 

Userlevel 1
Badge +6

Hi @spurl 

 

this i the thing i can think off

 

Qualtrics.SurveyEngine.addOnload(function() {

    // Function to handle click event on "Accept All" button

    var acceptAllButton = document.getElementById("QR~QID_of_question_3~1");

    acceptAllButton.onclick = function() {

        // Select "Accept" option for questions 1 and 2

        document.getElementById("QR~QID_of_question_1~1").click();

        document.getElementById("QR~QID_of_question_2~1").click();

    };

    // Function to handle click event on "Reject All" button

    var rejectAllButton = document.getElementById("QR~QID_of_question_3~2");

    rejectAllButton.onclick = function() {

        // Select "Reject" option for questions 1 and 2

        document.getElementById("QR~QID_of_question_1~2").click();

        document.getElementById("QR~QID_of_question_2~2").click();

    };

    // Function to handle click events on questions 1 and 2

    var question1 = document.getElementById("QR~QID_of_question_1");

    var question2 = document.getElementById("QR~QID_of_question_2");

    question1.onclick = function() {

        // Unclick "Accept All" and "Reject All" buttons

        acceptAllButton.checked = false;

        rejectAllButton.checked = false;

    };

    question2.onclick = function() {

        // Unclick "Accept All" and "Reject All" buttons

        acceptAllButton.checked = false;

        rejectAllButton.checked = false;

    };

});


i let me know this is what you want and if it works

Leave a Reply