Question
Use question responses to set embedded data
I only have a very basic understanding of javascript and, unfortunately, I'm having difficulty parsing the documentation that's available for adding custom javascript to questions/surveys and playing nicely with Qualtrics's built in functions.
What I want to accomplish is to set various embedded data values dependent upon people's responses to a single question or their responses to several questions.
So something along the lines of
if(response to question = X option){
Qualtrics.SurveyEngine.setEmbeddedData("Sex", "female");
}
or if ( (response to this.Question = X option) && (response to previous question = Y)){
Qualtrics.SurveyEngine.setEmbeddedData("Name", "Maria");
}
My major issues are:
- Figuring out how to get the question response in a form that I can use in logic flows
- Ensuring that changes in question responses will trigger an update of the embedded data (Note: We're not allowing to go back and change answers)
- Where this script should "live." The last question on the page where I'm setting values? The header? Individual questions?
- Being able to "import" responses from previous questions.
Some script that I have (unsuccessfully) tried in a single question's JS:
`if(JQuery("#"+this.questionid+"input.radio:checked").attr("choiceid") == "ch50644442"){
Qualtrics.SurveyEngine.setEmbeddedData("Sex","male");
}
if(jQuery("#"=this.questionID+"input.radio:checked").attr("choiceid") == "ch71012133"){
Qualtrics.SurveyEngine.set.EmbeddedData("Sex","female");
}`
`Qualtrics.SurveyEngine.addOnUnload(function(){
var pick;
jQuery("selct").on('click change', function(){
pick = (jQuery("select:eq(1):selected").text());
pick = (jQuery("select:eq(2):selected").text());
});
if(pick == "Male"){
Qualtrics.SurveyEngine.setEmbeddedData("Sex","male");
}
if(pick == "Female"){
Qualtrics.SurveyEngine.setEmbeddedData("Sex","female");
}
);}`
I should note that while I value elegant code, the most important thing for me is that I can understand it and potentially modify it for use in future studies. I also understand that I'm essentially asking someone to help me more or less from the ground up and that that may be a significant time investment. I just figured I'd start here, just in case the answer is so simple/blindingly obvious that it could be a quick fix for someone who is more knowledgeable than I am.
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
