Copy link to clipboard
Copied
Hello,
I am facing strange problem across all PDF Forms which i make via javascript.
The number fields instead of getting sum it gets concanated.
Please watch the below video to get clear picture of what is the problem.
Dropbox - concatenation problem.avi
basically i had to get the average of the number of fields filled by user......
The following is the script i used:
var counter = 0;
for (i=11; i<=20; i++) {
if (/^\s*$/.test(this.getField(i).valueAsString)==true) counter++;
}
if (counter>0) {
var total = counter;
} else total = "";
var v2 = 10 - total; // to get the number of filled fileds
var v1 = this.getField("11").value + this.getField("12").value + this.getField("13").value + this.getField("14").value + this.getField("15").value + this.getField("16").value + this.getField("17").value + this.getField("18").value + this.getField("19").value + this.getField("20").value; // sum of all the fields
event.value = v2 !== 0 ? v1 / v2 : ""; //average = sum/number of filled fields
Thanks in advance
1 Correct answer
Use this:
var v1 = Number(this.getField("11").valueAsString) + Number(this.getField("12").valueAsString) + ...
Copy link to clipboard
Copied
Use this:
var v1 = Number(this.getField("11").valueAsString) + Number(this.getField("12").valueAsString) + ...
Copy link to clipboard
Copied
Thanks That worked...
Thanks a lot

