Creating a embedded data in the same page to pipe in a next page | XM Community
Skip to main content

I have two mutiple choice questions (Yes/No) that shows in a same page. Based in if they are rated yes or not I created a embbeded variable that get a specific value. Then I want to use this embedded data to pipe in a next question. I can do this with a hidden question, but I want to create the embedded data in the same page that are the questions and then use this embedded data in the following page. Unfortunatenly, this is not working. So far, this is my code based in other posts that I read:

 

Qualtrics.SurveyEngine.addOnPageSubmit(function() {
var ans="";
var qid111 = jQuery("#QID111 .InputText").val();
var qid110 = jQuery("#QID110 .InputText").val();

    if (qid110 == "Yes" && qid111 == "No") {
        ans = "low interest";
    } else if (qid110 == "No" && qid111 == "Yes") {
        ans = "low mood";
    } else if (qid110 == "Yes" && qid111 == "Yes") {
        ans = "low mood and low interest";
    }

Qualtrics.SurveyEngine.setEmbeddedData("affect", ans);
});

 

Note that this code is in the same page that questions QID110 and QID111. I want to pipe “affect” embeded data in the next page (or question QID112) lke this:

 

You said that you feel with ${e://Field/affect} ... 

      

@Josang The code does work!

Not sure where you’re facing the issue. Try to check in console the value if the code is getting triggered or not.

Hope it helps!


@Josang The code does work!

Not sure where you’re facing the issue. Try to check in console the value if the code is getting triggered or not.

Hope it helps!

Thanks @Deepak, my issue is when I use preview and I answered yes in QID111 and/or QID110 I did not get any text expected in QID112 (i.e. “low interest”, “low mood” or “low mood and low interest”) “You said that you feel with ${e://Field/affect} ... “, just a blank space like there is not saved a embedded data. I figure out that if I use this javascript code in a next page (QID112) and then I use the embedded data in the next query (QID113) ${e://Field/affect} works. So, my impression is that is not saving this during the same page when I am answering QID110 and QID111. Not sure how to use console to see if this works, I am a newbee in Javascript/Qualtrics. Can you say how did you test this code?


I have two mutiple choice questions (Yes/No) that shows in a same page. Based in if they are rated yes or not I created a embbeded variable that get a specific value. Then I want to use this embedded data to pipe in a next question. I can do this with a hidden question, but I want to create the embedded data in the same page that are the questions and then use this embedded data in the following page. Unfortunatenly, this is not working. So far, this is my code based in other posts that I read:

 

Qualtrics.SurveyEngine.addOnPageSubmit(function() {
var ans="";
var qid111 = jQuery("#QID111 .InputText").val();
var qid110 = jQuery("#QID110 .InputText").val();

    if (qid110 == "Yes" && qid111 == "No") {
        ans = "low interest";
    } else if (qid110 == "No" && qid111 == "Yes") {
        ans = "low mood";
    } else if (qid110 == "Yes" && qid111 == "Yes") {
        ans = "low mood and low interest";
    }

Qualtrics.SurveyEngine.setEmbeddedData("affect", ans);
});

 

Note that this code is in the same page that questions QID110 and QID111. I want to pipe “affect” embeded data in the next page (or question QID112) lke this:

 

You said that you feel with ${e://Field/affect} ... 

      

The class .InputText is used for text input. It isn’t valid for a MC question.

You could find the checked choice in each question and use the choiceid from each question in your if statements. It would be something like:

var qid111 = jQuery("#QID111 inputptype=radio]:checked").attr("choiceid");

 


@Josang The code does work!

Not sure where you’re facing the issue. Try to check in console the value if the code is getting triggered or not.

Hope it helps!

Thanks @Deepak, my issue is when I use preview and I answered yes in QID111 and/or QID110 I did not get any text expected in QID112 (i.e. “low interest”, “low mood” or “low mood and low interest”) “You said that you feel with ${e://Field/affect} ... “, just a blank space like there is not saved a embedded data. I figure out that if I use this javascript code in a next page (QID112) and then I use the embedded data in the next query (QID113) ${e://Field/affect} works. So, my impression is that is not saving this during the same page when I am answering QID110 and QID111. Not sure how to use console to see if this works, I am a newbee in Javascript/Qualtrics. Can you say how did you test this code?

I thought you are using two open texts, you can follow tom G approach for MC type questions 


@Josang The code does work!

Not sure where you’re facing the issue. Try to check in console the value if the code is getting triggered or not.

Hope it helps!

Thanks @Deepak, my issue is when I use preview and I answered yes in QID111 and/or QID110 I did not get any text expected in QID112 (i.e. “low interest”, “low mood” or “low mood and low interest”) “You said that you feel with ${e://Field/affect} ... “, just a blank space like there is not saved a embedded data. I figure out that if I use this javascript code in a next page (QID112) and then I use the embedded data in the next query (QID113) ${e://Field/affect} works. So, my impression is that is not saving this during the same page when I am answering QID110 and QID111. Not sure how to use console to see if this works, I am a newbee in Javascript/Qualtrics. Can you say how did you test this code?

 

Thank you!

This is the code that I use to the end and works!

Qualtrics.SurveyEngine.addOnPageSubmit(function() {
var ans="";
    
var qid111 = jQuery("#QID111 input1type=radio]:checked").attr("choiceid");
var qid110 = jQuery("#QID110 input1type=radio]:checked").attr("choiceid");
    
    if (qid110 == "2" && qid111 == "1") {
        ans = "low interest";
    } else if (qid110 == "1" && qid111 == "2") {
        ans = "low mood";
    } else if (qid110 == "2" && qid111 == "2") {
        ans = "low mood and low interest";
    }

Qualtrics.SurveyEngine.setEmbeddedData("affect", ans);
});

 

 


Leave a Reply