display a pop message on screen when a particular response is given | XM Community
Skip to main content

Hi everyone!
I'm trying to have a pop-up message on the screen upon selection of a particular answer for a multiple-choice question.
I'm trying to see if I can change participants' responses after the warning message, so it is important to record their first choices and whether they changed their minds or not.
If choice #1 is selected, I need a pop message to show on the screen at the moment the participant select that choice.
I need Qualtrics to record the response they selected that caused the pop up to appear, and
I need to provide an opportunity for participants to change their choices after seeing the pop up message.
I need that both the first choice and second choice to be recorded.
I tried this:
var that = this;
var msg = 'INSERT ERROR TEXT HERE';
jQuery("#NextButton").on('click',function(){
var correctrecode = 8;
var choiceid = jQuery("#"+that.questionId+" input[type='radio']:checked").attr("choiceid");
var selectedrecode = that.getChoiceRecodeValue ( choiceid );
if(correctrecode==selectedrecode){
alert(msg);
}

});
Unfortunately, this is not what I need because it does not provide a chance for participants to change their choices.
Also, I would like the pop message to show up in the middle of the screen, not at the top.
Any help will be appreciated. My JavaScript knowledge is very limited.
Thank you!
Angélica

I can't help you with the alert message because you haven't specified how you'll be determining for which option the alert message pops up. You can use the following JS for recording the choices:
Qualtrics.SurveyEngine.addOnReady(function () {
    let choice_array = r];
    this.questionclick = function (ev, el) {
        if (el.id.match(/^QR~QID\\d+~\\d+~\\d+$|^QR~QID\\d+~\\d+$/gm)) {
            choice_array.push(el.id);
            Qualtrics.SurveyEngine.setEmbeddedData("choice_array", choice_array.join(","));
        }
    };
});
This will create an embedded data called choice_array, which will contain every choice made by your subjects. This will record using the internal Qualtrics ids, and you can then use the inspector to figure out which id corresponds to which choice.


Hi ahmedA, I really apreciate your help!
I apologize for not providing more details.
I have 18 multiple-choice questions, each one has only two options: share it x not share it. Every time a participant chooses "share it", the pop-up should show: "are you sure?". Then this participant would have to choose between: "yes" and "no, I don't want to share it anymore".
Right now, I am using in-page display logic. But I would like the "are you sure" part to be a popup message. I don't even know if this is possible.
Thank you for your time
All the best, Angélica


Try this JS:
Qualtrics.SurveyEngine.addOnReady(function () {
    let relevant_choice = this.questionContainer.querySelectorAll("li")A0];
    relevant_choice.onclick = function (click) {
        let recall = confirm("Do you really want to share?");
        if (!recall) click.preventDefault();
    };
});

You may have to change the 0 to 1 based on your arrangement.


ahmedA Hi, any way to make this work for all answer choices, instead of just one?


https://community.qualtrics.com/XMcommunity/discussion/comment/35855#Comment_35855Hi ahmedA ,
This code works perfectly, is there any way to have a Yes No buttons instead of OK Cancel in the popup Alert message.
Your help is much appreciated.


Yes, but that'll require custom programming. This one is using the browser's inbuilt pop-ups, therefore, it's just 3 lines of code.


https://community.qualtrics.com/XMcommunity/discussion/comment/55978#Comment_55978Thanks for the response. I have requirement where on clicking particular answer choices pop-up question should come as Do you want to share? with Yes No buttons instead OK Cancel.
Your help is much appreciated in custom coding.


Drop me a pm with the details and we can discuss it.


Hi everyone!
I'm trying to have a pop-up message on the screen upon selection of a particular answer for a multiple-choice question.
I'm trying to see if I can change participants' responses after the warning message, so it is important to record their first choices and whether they changed their minds or not.
If choice #1 is selected, I need a pop message to show on the screen at the moment the participant select that choice.
I need Qualtrics to record the response they selected that caused the pop up to appear, and
I need to provide an opportunity for participants to change their choices after seeing the pop up message.
I need that both the first choice and second choice to be recorded.
I tried this:
var that = this;
var msg = 'INSERT ERROR TEXT HERE';
jQuery("#NextButton").on('click',function(){
var correctrecode = 8;
var choiceid = jQuery("#"+that.questionId+" input[type='radio']:checked").attr("choiceid");
var selectedrecode = that.getChoiceRecodeValue ( choiceid );
if(correctrecode==selectedrecode){
alert(msg);
}

});
Unfortunately, this is not what I need because it does not provide a chance for participants to change their choices.
Also, I would like the pop message to show up in the middle of the screen, not at the top.
Any help will be appreciated. My JavaScript knowledge is very limited.
Thank you!
Angélica

Hi there, I am using this piece of code and it first works well.

But it seems that I need to click on “Ok” twice for the window to disappear. The button “Cancel” works fine and only needs one click.

How can I fixe this?

 

Thank you


Leave a Reply