Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Fields get concanated instead of adding the numbers

Engaged ,
Feb 23, 2019 Feb 23, 2019

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

TOPICS
Acrobat SDK and JavaScript , Windows
615
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 24, 2019 Feb 24, 2019

Use this:

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

Translate
Community Expert ,
Feb 24, 2019 Feb 24, 2019

Use this:

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 24, 2019 Feb 24, 2019
LATEST

Thanks That worked...

Thanks a lot

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines