If you are going to calculate values and present them, you should put them into a descriptive text question instead of an actual question. You can use rich text formatting to achieve the matrix look by putting the text and the calculated values into a table.
Create embedded data (in survey flow) elements for children, adults, senior, and total. Set the values from the question, and put the embedded data into the display table.
WaterSampler: Thanks for your response. I will use rich text formatting to achieve the look I want (instead of using an actual question). I still am uncertain of how to link these javascript calculations to embedded text. I don't think I can make these calculations in the survey flow, but correct me if I am wrong. This is what my javascipt looks like:
Qualtrics.SurveyEngine.addOnReady(function()
{
// 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 for all the adults
let adult1;
if (age1 > 17) {
adult1 = 1;
} else {
adult1 = 0;
}
let adult2;
if (age2 > 17) {
adult2 = 1;
} else {
adult2 = 0;
}
let adult3;
if (age3 > 17) {
adult3 = 1;
} else {
adult3 = 0;
}
//total all the adults
let adults=adult1+adult2+adult3;
Qualtrics.SurveyEngine.setEmbeddedData("adults",adults_tot);
});
After I include this script I am unable to access it as embedded text and then have it show up in the survey. Do you have any suggestions? Thank you.
Thanks again! This is great and clarifies a few things, but I still can't get the embedded data to show up in the survey in real time. More specifically, I am hoping that the values are calculated once the respondent answers the age question (from a drill down list, is this a problem?)
To clarify, I do have the embedded values in the survey flow:
!
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.
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.
Thanks for all the input. Adding a block break solved all the issues. I had hoped to have this show up on the same page, but this will work as well.