This is how it works. First the respondent enters in the names, ages and gender of the respondents (morador is household member)
!
The next question (in a new block) includes the javascript and pipes in the embedded text and answers to individual survey questions.
!
The indivudal age values show up, suggesting that the data are being read, but the javascipt calculations do not. This is what I see (notice the ages are listed, but the calcualtions are blank):
!
This is my javascript (I tried it in the Onload and OnReady sections – neither works)
Qualtrics.SurveyEngine.addOnload(function()
{
// These lines read in the entered data on age
let age1= "${q://QID8%232/ChoiceTextEntryValue/1/1}";
let age2= "${q://QID8%232/ChoiceTextEntryValue/2/1";
let age3= "${q://QID8%232/ChoiceTextEntryValue/3/1}";
// create age variables
let adults = 0;
let kids = 0;
let seniors = 0;
if (age1 > 17 && age1 < 64) { adults++;} else if (age1 <= 17) { kids++;} else {seniors++;}
if (age2 > 17 && age2 < 64) { adults++;} else if (age2 <= 17) { kids++;} else {seniors++;}
if (age3> 17 && age3< 64) { adults++;} else if (age3 <= 17) { kids++;} else {seniors++;}
let family=adults+kids+seniors
Qualtrics.SurveyEngine.setEmbeddedData("adults",adults);
Qualtrics.SurveyEngine.setEmbeddedData("kids",kids);
Qualtrics.SurveyEngine.setEmbeddedData("seniors",seniors);
Qualtrics.SurveyEngine.setEmbeddedData("family", family);
});
And, to confirm, the embedded text is in the survey flow:
!
Any suggestions on what is wrong here? I tried entering in the ages as text (to add to a box as noted above) and from a drop down menu. Neither works.
Thanks for any suggestions!
Best answer by WaterSampler
View original