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

adding

Explorer ,
Sep 01, 2020 Sep 01, 2020

Copy link to clipboard

Copied

Is there any mistake in this script?

I wanted to add few variables in a pdf form, but it is not working: (I am a learner)

 

(this.getField("A").value)*10+ (this.getField("B").value)/3.5+

(this.getField("C").value)*2+

(this.getField("D").value)/2+

(this.getField("E").value)/4+

(this.getField("F").value)/0.227+

(this.getField("G").value)/2+ ((this.getField("H").value)||(this.getField("I").value))+

((this.getField("Text1").value)||(this.getField("Text2").value) ||(this.getField("Text3").value));

 

Thanks,

TOPICS
Acrobat SDK and JavaScript

Views

527

Translate

Translate

Report

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 2 Correct answers

Community Expert , Sep 01, 2020 Sep 01, 2020

Hi, you can add this before your code: event.value  =

Also you need to add "Number" to your fields like this: Number(this.getField("A").value or with your current code fields J,K,L won't calculate unless there is value in H or I.

Or if you don't know how to do it, just use this code:

var a = Number(this.getField("A").value);
var b = Number(this.getField("B").value);
var c = Number(this.getField("C").value);
var d = Number(this.getField("D").value);
var e = Number(this.getField("E").value);
var f = Numbe

...

Votes

Translate

Translate
Community Expert , Sep 01, 2020 Sep 01, 2020

Using the OR operator in such a calculation is really asking for problems. If they are "interchangable" and only one of them can have a value at any specific point then just add them up. The result of their sum should be the value of the one field that has a value from the group, and it will be much easier to follow and debug.

Votes

Translate

Translate
Enthusiast ,
Sep 01, 2020 Sep 01, 2020

Copy link to clipboard

Copied

What are you trying to achive?

Votes

Translate

Translate

Report

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
Explorer ,
Sep 01, 2020 Sep 01, 2020

Copy link to clipboard

Copied

just a simple addition with multiplication and division and adding some fields if they are available only (I used OR for that because they are interchangeable).

Votes

Translate

Translate

Report

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
Enthusiast ,
Sep 01, 2020 Sep 01, 2020

Copy link to clipboard

Copied

What is the name of the field where you use this script?

Are all fields values number or are there text also?

 

EDIT: Forgot to ask, what is deciding factor between "I" or "H" and between "Text1" or "Text2" or "Text3"?

Votes

Translate

Translate

Report

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
Explorer ,
Sep 01, 2020 Sep 01, 2020

Copy link to clipboard

Copied

The name of the field is TOTAL, I wanted it in the custom calcutation.

they are all numbers, no text at all

 

Votes

Translate

Translate

Report

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
Enthusiast ,
Sep 01, 2020 Sep 01, 2020

Copy link to clipboard

Copied

Hi, not sure if you saw my edited post so il ask again. How do you want  script to choose between H or I and between Text1 or Text2 or Text3?

Votes

Translate

Translate

Report

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
Explorer ,
Sep 01, 2020 Sep 01, 2020

Copy link to clipboard

Copied

those field are linked to a checkbox: if it is marked it will display the value in I or H. the same for J, K, L

(there is no text it is my mistake they are all numbers: so the last line would be

((this.getField("J").value)||(this.getField("K").value) ||(this.getField("L").value));

Votes

Translate

Translate

Report

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
Community Expert ,
Sep 01, 2020 Sep 01, 2020

Copy link to clipboard

Copied

You can try the script in the Javascript Debugger.

Votes

Translate

Translate

Report

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
Community Expert ,
Sep 01, 2020 Sep 01, 2020

Copy link to clipboard

Copied

Hi, you can add this before your code: event.value  =

Also you need to add "Number" to your fields like this: Number(this.getField("A").value or with your current code fields J,K,L won't calculate unless there is value in H or I.

Or if you don't know how to do it, just use this code:

var a = Number(this.getField("A").value);
var b = Number(this.getField("B").value);
var c = Number(this.getField("C").value);
var d = Number(this.getField("D").value);
var e = Number(this.getField("E").value);
var f = Number(this.getField("F").value);
var g = Number(this.getField("G").value);
var h = Number(this.getField("H").value);
var i = Number(this.getField("I").value);
var j = Number(this.getField("J").value);
var k = Number(this.getField("K").value);
var l = Number(this.getField("L").value);
event.value = (a*10)+(b/3.5)+(c*2)+(d/2)+(e/4)+(f/.227)+(g/2)+(h||i)+(j||k||l);

Votes

Translate

Translate

Report

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
Community Expert ,
Sep 01, 2020 Sep 01, 2020

Copy link to clipboard

Copied

Using the OR operator in such a calculation is really asking for problems. If they are "interchangable" and only one of them can have a value at any specific point then just add them up. The result of their sum should be the value of the one field that has a value from the group, and it will be much easier to follow and debug.

Votes

Translate

Translate

Report

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
Explorer ,
Sep 04, 2020 Sep 04, 2020

Copy link to clipboard

Copied

LATEST

You are right, I just added them.

Thanks

Votes

Translate

Translate

Report

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