Question
javascript matrix table get choice value as number
Hi, I'd like to conditionally assign participants to 1 of 8 items based on how familiar they are with each of the 8 items.
In my Qualtrics survey, participants first rate all 8 items using a Matrix Table question. I'd like to use those ratings to conditionally assign participants to 1 item (i.e., if else statements).
Because I want to make a list of items that satisfy my "familiar" or "unfamiliar" definitions, I have to use JavaScript.
I've added my JavaScript code to a question that comes after the rating Matrix Table question (QID22) so that I can refer to recoded answers from that matrix question.
Below, I've included only a small part of my JavaScript code because this code doesn't work like I expect it to.
The possible recoded values range from 0-3 by units of 1 (i.e., 0, 1, 2, 3). When I preview my survey, my embedded data don't have any values from 0 to 3. When convert SelectedAnswerRecode values to numbers with the Number function (e.g., Number("${q://QID22/SelectedAnswerRecode/1}")), my embedded data have only 0 values. I've also tried parseInt() and parseFloat() without luck (both give seemingly "blank" embedded data values).
I'm not sure what to do from here. Does anyone have any ideas? Thank you!
Qualtrics.SurveyEngine.addOnload(function() {
/*Place your JavaScript here to run when the page loads*/
});
Qualtrics.SurveyEngine.addOnReady(function() {
// save every answer choice into an object
var item1 = "${q://QID22/SelectedAnswerRecode/1}";
var item2 = "${q://QID22/SelectedAnswerRecode/2}";
var item3 = "${q://QID22/SelectedAnswerRecode/3}";
var item4 = "${q://QID22/SelectedAnswerRecode/4}";
var item5 = "${q://QID22/SelectedAnswerRecode/5}";
var item6 = "${q://QID22/SelectedAnswerRecode/6}";
var item7 = "${q://QID22/SelectedAnswerRecode/7}";
var item8 = "${q://QID22/SelectedAnswerRecode/8}";
// save all values as embeded data
Qualtrics.SurveyEngine.setEmbeddedData("item1", (item1));
Qualtrics.SurveyEngine.setEmbeddedData("item2", (item2));
Qualtrics.SurveyEngine.setEmbeddedData("item3", (item3));
Qualtrics.SurveyEngine.setEmbeddedData("item4", (item4));
Qualtrics.SurveyEngine.setEmbeddedData("item5", (item5));
Qualtrics.SurveyEngine.setEmbeddedData("item6", (item6));
Qualtrics.SurveyEngine.setEmbeddedData("item7", (item7));
Qualtrics.SurveyEngine.setEmbeddedData("item8", (item8));
// if () and if else () logic follows
});
Qualtrics.SurveyEngine.addOnUnload(function() {
/*Place your JavaScript here to run when the page is fully displayed*/
});
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
