Essentially I have a calculated field that I want to end up with a rating %.
That rating % is going to be based on the values selected from a series of dropdowns in a subform. The drop downs have values from 0 to 5. Drop downs with a value of 0 are to be ignored and not included in the calculation.
For example, if there are 5 drop downs and 1 has a selcted value of 0, the rating percentage would be based on the values of 4 of the drop downs out of a maximum score of 20.
Here is what I have so far in the calculated field:
var Fields = xfa.resolveNodes("Page2.Comm_Sub.CommRtng[*]");
var Answered = 0;
var Values = 0;
var Rating = (Values / (Answered*5)) * 100
for (i=0; i<= Fields.length; i++){
if (Fields.item(i).rawValue > 0) {
Answered++;
Values += Fields.item(i).rawValue;
}
}
this.rawValue = Rating
As I said, it's a pretty basic loop (I think), but I cannot get it to output a value in Answered or Values or Rating or at least I don't think it is. For instance when I input xfa.host.messageBox(Answered) in the code to see what's happening, I only ever get a blank messageBox, same when I use "Values". So I know the loop is running, but it doesn't seem to be grabbing anything and updating the variables.
I'm also thinking that I have a glaring omission in the code that does not account for users going back and changing an entry. I think that will throw the Answered variable off. However, I have no idea how to account for that.
I'm trying to keep the code as basic as possible as 1. I'm exactly a master of JavaScript and 2. I have upwards of 20 different ratings to find across 12 different foms, where the number of drop downs relating to each rating can vary. So the more compact and easy to understand I can make it the better.
I have a sample PDF that I can send to anyone if that will help.