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.
Page 1 / 1
I'm no coding guru but it sounds like you could do this very easily with just branching logic and Embedded Data:
> * Figuring out how to get the question response in a form that I can use in logic flows
If you use branching logic, this is done automatically and you just click Question and then select which one you want to use for your logic and then the type of data related to that question (question text, selected answers, answer text, etc).
> * 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)
You can do this by putting your embedded data/branching after each question block in the survey flow
> * Where this script should "live." The last question on the page where I'm setting values? The header? Individual questions?
If you do this with branching, I'd recommend right after each question block.
> * Being able to "import" responses from previous questions.
Again, this is done automatically: You can flow it into your branch from the default survey flow.
Holler if you need assistance with how to set that up. I'd be happy to walk you through an example, if you need it!
> * Figuring out how to get the question response in a form that I can use in logic flows
If you use branching logic, this is done automatically and you just click Question and then select which one you want to use for your logic and then the type of data related to that question (question text, selected answers, answer text, etc).
> * 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)
You can do this by putting your embedded data/branching after each question block in the survey flow
> * Where this script should "live." The last question on the page where I'm setting values? The header? Individual questions?
If you do this with branching, I'd recommend right after each question block.
> * Being able to "import" responses from previous questions.
Again, this is done automatically: You can flow it into your branch from the default survey flow.
Holler if you need assistance with how to set that up. I'd be happy to walk you through an example, if you need it!
I would like to be able to do this as well without having to use branching and blocks as I want to keep the blocks to signify sections not having to deal with many blocks. I guess its just the way its designed.
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.