Hello, I am currently having issue getting this bit of code working. I am trying to take the average of four other embedded data variables, all of which are calculated during the survey.
I have four questions on one page that ask for the four values ("holdtoground1" etc.) to take the average of. Here is an example of the javascript for one of them:
Qualtrics.SurveyEngine.addOnPageSubmit(function() {
var answer = document.getElementById('QR~' + this.questionId);
Qualtrics.SurveyEngine.setEmbeddedData( 'holdtoground3', answer.value );
});
On the fourth question, I also use javascript to calculate the average of these four variables ("holdtogroundBL"), which I think is where the issue is.
Qualtrics.SurveyEngine.addOnPageSubmit(function() {
var answer = (document.getElementById('QR~' + this.questionId)).value;
Qualtrics.SurveyEngine.setEmbeddedData( 'holdtoground4', answer );
//calculate overall hold to ground time
var item1 = parseInt("${e://Field/holdtoground1}");
var item2 = parseInt("${e://Field/holdtoground2}");
var item3 = parseInt("${e://Field/holdtoground3}");
var sum = item1 + item2 + item3 + answer.value
var average = sum / 4.0;
Qualtrics.SurveyEngine.setEmbeddedData( 'holdtogroundBL', average);
});
The problem is that I want to show the user that average on the next page, so after a page break I have displayed text that looks like this:
But, while the four smaller variables load, the average does not:
Can anyone tell me what my issue is? I made sure to set all the embedded data variables as Numbers, and even have them default to 0.
How to set an embedded data variable as an average of other embedded data variables
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
