I have created embedded variables giving a specific text if certain questions are answered with yes. However, I have found that I can only use the embedded variables I create in to the next block (using the piped text $e{field//NameVariable}) but in a same block where the questions are answered I have not been able to.
I have tried to call the embedded variable within the same block is created using javascript with the following code:
Qualtrics.SurveyEngine.addOnload(function(){ var myEmbeddedData = "${e://Field/myEmbeddedData}"; });
or
`Qualtrics.SurveyEngine.addOnload(function(){
let myEmbeddedData = Qualtrics.SurveyEngine.getEmbeddedData("myEmbeddedData").
});`
And then I tried to place in the next query, as piped text, my embbedData like this:
Hi this is your answer ${e://Field/myEmbeddedData}
But when I click on preview, I don't see the results, just a blank space. Note that if I use this text in the next block, it works.
Thanks in advance!
EDIT:
I am trying to use the following code of javascript in a page after the evaluated questions QID110 and QID111:
var ans = "";
var qid110 = "${q://QID110/ChoiceGroup/SelectedChoices}";
var qid111 = "${q://QID111/ChoiceGroup/SelectedChoices}";
if (qid110 == "Yes" && qid111 == "No") {
ans = "a";
} else if (qid110 == "No" && qid111 == "Yes") {
ans = "b";
} else if (qid110 == "Yes" && qid111 == "Yes") {
ans = "c";
}
Qualtrics.SurveyEngine.setEmbeddedData("test", ans);
in the following page of the javascript I try to pipe the embedded data in the query like this:
This is you answer ${e://Field/test}
But the result is also in blank. So, maybe I am coding wrong. Any help?
This was the code that works for me:
Qualtrics.SurveyEngine.addOnPageSubmit(function() {
var ans="";
var qid111 = jQuery("#QID111 input[type=radio]:checked").attr("choiceid");
var qid110 = jQuery("#QID110 input[type=radio]:checked").attr("choiceid");
if (qid110 == "2" && qid111 == "1") {
ans = "a";
} else if (qid110 == "1" && qid111 == "2") {
ans = "b";
} else if (qid110 == "2" && qid111 == "2") {
ans = "c";
}
Qualtrics.SurveyEngine.setEmbeddedData("test", ans);
});