Skip to main content
rakeshk21205956
Inspiring
February 24, 2019
Answered

Fields get concanated instead of adding the numbers

  • February 24, 2019
  • 1 reply
  • 689 views

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

This topic has been closed for replies.
Correct answer Bernd Alheit

Use this:

var v1 = Number(this.getField("11").valueAsString) + Number(this.getField("12").valueAsString) + ...

1 reply

Bernd Alheit
Community Expert
Bernd AlheitCommunity ExpertCorrect answer
Community Expert
February 24, 2019

Use this:

var v1 = Number(this.getField("11").valueAsString) + Number(this.getField("12").valueAsString) + ...

rakeshk21205956
Inspiring
February 24, 2019

Thanks That worked...

Thanks a lot