Skip to main content
Participating Frequently
November 8, 2016
Question

Javascript Adobe Acrobat Help

  • November 8, 2016
  • 11 replies
  • 864 views

Im looking for some help with javascript in my PDF.

I have multiple fields calculating other fields and I've come to a dead end. Usually the fields I'm working with are directly related to another field. I'll try to simplify the calculations to make things easier.

ex.

In Field "Text2", I could have a calculation,

("Text1" / 24)

In Text3, the calculation would be,

let var A = "Text1", let B = "Text2"

Var result= "A" - "B"

In Text4, I had a code to populate a number based on the number "Text3" shows. If i falls within a certain range, a number will show up.

If var is >0 and <=90 then "1 hour"

if  var is >90 and <=180 then "1:30 hour"

etc.

In Text 5, there is another calculation that is not related with any other fields shown above.

My problem now is that in Text5, sometimes a certain number populates which will then change "Text4". Usually Text 5 has nothing to do with Text4 but here it does.

How can i have an if statement within Text4 for those random occasions where specific numbers in Text 5 populate?

My problem is that there are already calculations that are incorporated with Text4 using numbers from other fields.

I really hope this made sense.

Any help would be greatly appreciated. Thanks in advance

This topic has been closed for replies.

11 replies

try67
Community Expert
Community Expert
November 8, 2016

You can use an if-statement. The general structure of the code will be something like this:

if Text5==special value

     Text4 = special calculation

else Text4 = normal calculation

This would mean that you need to place Text5 before Text4 in the fields calculation order list, though.

Participating Frequently
November 8, 2016

This is what have currently. Its grabing a value from "Text8". i already have an if statement.

How can i say if in "Text5", if the number is 243, make event.value "2:00"

event.value = "";

var s = this.getField("Text8").value;

if (s!="") {

     var v = Number(s);

     if (v>=0 && v<=60) event.value = "1:00";

     else if (v>60 && v<=90) event.value = "1:30";

     else if (v>90 && v<=120) event.value = "2:00";

     else if (v>120 && v<=150)

event.value = "2:30";

     else if (v>150 && v<=180)

event.value = "3:00";

     else if (v>180 && v<=210)

event.value = "3:30";

    

}

try67
Community Expert
Community Expert
November 8, 2016

I don't understand your code... What calculation script is this?