
Solved
use survey responses for real time calculations
I would like to use survey responses in the calculation of values that then are presented in the survey in real time. I cannot figure out how to show these values in the survey. Should I create the new value as embedded data (in the survey flow) and then add this as piped text or should I use javascript to create a new value that is then set as embedded with (Qualtrics.SurveyEngine.setEmbeddedData("Total",sum_total) in the javascript? I have tried both options and cannot get the calculated values to show up in the survey. These are the calculations I'd like to make:
Take all the family members who are entered with age into a matrix table (drop down choice for age) and summarize them into three categories: kids, adults, seniors. The objective is for these three values to be provided in the survey so the respondent can confirm the answers. (See screen shot below).
!

Best answer by WaterSampler
To use alert, insert a statement where you want to debug or see the values.
e.g., before creating dummy variables you might say:
alert("age1 recorded as"+age1);
When you preview the survey, you will get a popup showing you what value age1 was set to.
You might have to move the JS to Q3 addOnload. That way Q1 will have all data entered. As you suggested, Q3 might have to be on a new page to insure that all the data from Q1 is in the system.
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.

This is how the questions look now:
!
I have the javscript added to Q1 (onReady section) and have the piped text added to Q3. When I use the preview and select ages no calculations show up in Q3 (not even a 0 value).
My javascript is here. (I am not sure how to use alert).
Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
// These lines read in the entered data on age
let age1="${q://QID1%231/ChoiceGroup/SelectedChoicesForAnswer/1}";
let age2="${q://QID1%231/ChoiceGroup/SelectedChoicesForAnswer/2}";
let age3="${q://QID1%231/ChoiceGroup/SelectedChoicesForAnswer/3}";
// create dummy 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++;}
Qualtrics.SurveyEngine.setEmbeddedData("adults",adults);
Qualtrics.SurveyEngine.setEmbeddedData("kids",kids);
Qualtrics.SurveyEngine.setEmbeddedData("seniors",seniors);
});
Is there an issue with using drill down values? Do I need to add this to a new block or page? I'm at a loss as to why this is not working. Thanks for any advise.