Skip to main content
Participating Frequently
September 19, 2017
Question

Basic Calculation & Display Text (Custom Calculation script)

  • September 19, 2017
  • 2 replies
  • 2344 views

Ok, I've been searching for 3 days on this answer, but everytime I change something I break my form again.

I have 4 text boxes:

Two with Currency variables.

In the 3rd box, they need to subtract in.

In the 4th box, it needs to display Over/Short/Balanced

I've got the form working with just that information. My problem is that if the first two boxes are blank, the other two need to be blank. Or in otherwords, if a calculation hasn't taken place, Box 3 & 4 need to remain blank till Box 1 & 2 are populated.

In Box 3 for the Calculation Script, I've got this:

event.value = ( this.getField("Actual_Cash_in_TCR").value - this.getField("TCR_Reported_Totals").value );

In Box 4 for the Calculation Script, I've got this:

var n = this.getField("Amount").value;

if( n > 0) event.value = "Over";

else if ( n < 0) event.value = "Short";

else event.value = "Balanced";

Where am I messing up, what needs to be added and where?

Adobe Acrobat Pro DC 2015.006.30355 for Windows.

This topic has been closed for replies.

2 replies

Participating Frequently
September 20, 2017

Maybe this will help?

Sample.pdf - Google Drive

try67
Community Expert
Community Expert
September 20, 2017

- You're not using the code we gave you. You still have the same error I mentioned in my first reply!

This is incorrect:

else if ( val3 = 0 ){

Either you follow our advice or don't, but don't say you do and then don't and say it's not working... That's very frustrating.

- Also, your field calculation order is incorrect. "Over-Short" needs to be calculated after "Amount".

Participating Frequently
September 20, 2017

This is what I have in now (unless I missed something)...

What do you mean about Field Calculation? I'm not trying to not follow advice, just getting it in different formats.

try67 looks like what I was starting with, and Karl's looks like SQL, getting confused. (why I didn't go into programming).

var val1 = this.getField("Actual_Cash_in_TCR").valueAsString;

var val2 = this.getField("TCR_Reported_Totals").valueAsString;

var val3 = Number(this.getField("Amount").valueAsString);

console.println("val3 = " + val3);

if (val1 == "" || val2 == "") {

event.value = "";

}

else if ( val3 > 0 ) {

event.value = "Over" ;

}

else if ( val3 < 0 ) {

event.value = "Short";

}

else if ( Number(val3) == 0 ) {

event.value = "Balanced";

}

Karl Heinz  Kremer
Community Expert
Community Expert
September 19, 2017

You can use an if/else construct to find out if the source fields are filled in. Something like this should work:

var val1 = this.getField("Actual_Cash_in_TCR").valueAsString;

var val2 = this.getField("TCR_Reported_Totals").valueAsString;

if (val1 == "" || val2 == "") {

    event.value = "";

}

else {

    event.value = ( Number(val1) - Number(val2) );

}

Participating Frequently
September 19, 2017

I get SyntaxError: syntax error 3 for the "else" argument

Karl Heinz  Kremer
Community Expert
Community Expert
September 19, 2017

The code from above works for me. Can you please post the exact code you are using.