Hi All,
I am setting an embedded data value based on the selected value answer through the following JS on page submit event and update the mailing list accordingly with this value:
Qualtrics.SurveyEngine.addOnPageSubmit(function (type) {
if (type == "next") {
var x = "${e://Field/2nd_wave}";
if (x == ""){
var ans = this.getSelectedChoices();
if ( ans == "1")
{
Qualtrics.SurveyEngine.setEmbeddedData('x', "Yes");
}
else if ( ans == "2")
{
Qualtrics.SurveyEngine.setEmbeddedData('x', "No");
}
else
{
Qualtrics.SurveyEngine.setEmbeddedData('x', "");
}
}
}
});
My question, in above scenario, I am checking if (x == "") means empty. I would like to check also if another question on the same page has a specific answer. For example,
if Q1 (question on the same page) answered Yes and x == "", then apply the if statement otherwise no embedded date is set.
I tried to work with getting the SelectedValue using the pipped text but it seems that Qualtrics does not capture that as the previous question is on the same page.
Your insights and feedback is highly appreciated
Best Regards,
Muqaibil
In the addOnLoad of the other question, add something like,
q2 = this;This will make
q2a global variable on that page and you can extract the answers using the methods mentioned in the JS API.
https://community.qualtrics.com/XMcommunity/discussion/comment/42605#Comment_42605Thanks ahmedA for your reply.
I could not understand exactly what you provide. do you mean adding as followed in the other question!!?
Qualtrics.SurveyEngine.addOnLoad(function() {
q = this;
});
could you please tell me how to set the other question answer to be examined against the second question conditions? means, getting the first question answer to the second question in order to check it before setting the embedded data addOnPageSubmit event
To provide a solution, I'll need to see your survey preview.
ahmedA
here it is:
https://alj.eu.qualtrics.com/jfe/preview/SV_2nUy954B2G5ert4?Q_CHL=preview&Q_SurveyVersionID=current
I tried to minimize the options and questions to simplify the requirement.
Q2 displays when you select the first answer option.
As shown in the screen shot, on addOnPageSubmit(type==next) event; I want to check two conditions in the second question JS before apply it. first, "Booster_Dose" embedded data is empty and second if Q1 answer was equal to "1" to apply setting embedded data.
I am trying to do this in order to ensure that if someone answer both questions then select other option in first question. then Q2 JS will be valid to apply as its answer was selected then got just hidden by the in-page display logic applied with first Q1
I hope that clarifies my point..
Many thanks in advance for your support..
From the looks of it, you really don't need JS for this, it can be done via survey flow.
However, I'll write the code, please fill this up, as I don't understand the values your ED will take:
Muqaibil - Values
https://community.qualtrics.com/XMcommunity/discussion/comment/42667#Comment_42667Hi ahmedA
I know what you mean by doing the things through the survey flow but actually there a purpose of doing it through JS. I am changing the ED field frequently and update the mailing list with this new value to keep track respondents answers for every time they do the same survey.
I already have gone through survey flow option but it didn't work with the multiple skip logics and conditions there
Many thanks for your co-operation i really do appreciate that..
waiting for your guidance dear
Please add this JS to the second question, the one with the display logic.
Qualtrics.SurveyEngine.addOnPageSubmit(function () {
const quest = this;
const qc = quest.questionContainer;
document.querySelector("#NextButton").onmouseenter = function () {
if (qc.className.includes("hidden")) {
Qualtrics.SurveyEngine.setEmbeddedData("2nd_wave", "null");
} else {
const choices = quest.getChoices();
const selected = quest.getSelectedChoices();
const value = choices.indexOf(selectedc0]) === 0 ? "Yes" : "No";
Qualtrics.SurveyEngine.setEmbeddedData("2nd_wave", value);
}
};
});
Let me know if you face any issues.
https://community.qualtrics.com/XMcommunity/discussion/comment/42706#Comment_42706working perfect as expected. However, I am working on similar thing to simplify the approach. I will post it once i finish it dear ahmedA
Many thanks for your insights..
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.