Skip to main content
Participant
July 27, 2022
Answered

Average Rating Formula - Help

  • July 27, 2022
  • 2 replies
  • 651 views

I am trying to write a formula to calculate the average rating on a form, but I do not speak Java. I asked a co-worker for help and they gave me the following formula, but it is not working... Please help! 

 

var avgScore = 0;

var score1 = document.getElementById('Text2').value;
var score2 = document.getElementById('Text3').value;
var score3 = document.getElementById('Text4').value;
var score4 = document.getElementById('Text5').value;
var score5 = document.getElementById('Text6').value;

avgScore = (score1 + score2 * 2 + score3 * 3 + score4 * 4 + score5 * 5) / (score1 + score2 + score3 + score4 + score5);

Text1.value = avgScore;

 

 

I really have no clue here guys! Any help is appreciated! 

This topic has been closed for replies.
Correct answer Nesa Nurani

Replace this:

var score1 = document.getElementById('Text2').value;

with this:

var score1 = Number(this.getField("Text2").value);

if you use script in "Text1" field as custom calculation replace Text1.value with event.value.

You sure thats the formula you want to use to calculate average?

2 replies

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
July 28, 2022

Replace this:

var score1 = document.getElementById('Text2').value;

with this:

var score1 = Number(this.getField("Text2").value);

if you use script in "Text1" field as custom calculation replace Text1.value with event.value.

You sure thats the formula you want to use to calculate average?

Participant
July 29, 2022

I am not sure. This is what was suggested to me. It's not just a simple average. It is the average of a rating scale of 1-5 (unsatisfactory, needs improvement, above average, exceeds standards). 

But it does work with your fixes!!! Thank you SOOOO much!!! 

Bernd Alheit
Community Expert
Community Expert
July 28, 2022
  1.  Acrobat uses Javascript, not Java
  2.  You can't use browser Javascript in Acrobat.
Participant
July 29, 2022

All that is Greek to me. As I said, I really have NO clue. I am good at working with Microsoft apps, but I have just started developing forms in Adobe. I have zero IT knowledge and have never taken a class, nor have I ever been trained in Adobe. I know enough to be dangerous. I would LOVE the opportunity to learn more though!