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

Custom Calculation Script Help Please

Guest
Jan 17, 2018 Jan 17, 2018

Hello,

I have no experience with JavaScript. Can someone please help me with a custom calculation for a checkbook register? 

Example of Field Names used on each line of the form:

Amt1       Dep1     Bal1

Amt2       Dep2     Bal2

I've tried the following Simplified Field Notation:  BalanceForward - Amt1 + Dep1. This works on the first line of the form and then auto populates the balance field on each remaining line of the form. If there are no entries (check or deposit) I don't want to see the balance populated.

I've also tried the following JavaScript with similar results. The below works in the first line (Bal1 field), however when I change the script to reflect different field names it doesn't calculate and returns nothing.

Example of script in Bal1 field:

event.value=Number(this.getField("BalanceForward").value)-Number(this.getField("Amt1").value)+Number(this.getField("Dep1").value);

I think I need an If/Else statement in Bal2, Bal3, Bal4, etc. fields, however I don't know how to write it! If there are no entries in Amt2 or Dep2 then no balance (Bal2 field) should appear.

Thank you!

TOPICS
Acrobat SDK and JavaScript , Windows
703
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 , Jan 17, 2018 Jan 17, 2018

Hi.

Try this in Bal1 field (not tested):

var total = (this.getField("BalanceForward").value) - (this.getField("Amt1").value) + (this.getField("Dep1").value);

if (total != "NaN") {

    event.value = total;

}

else {event.value = "";}

Translate
Community Expert ,
Jan 17, 2018 Jan 17, 2018

Hi.

Try this in Bal1 field (not tested):

var total = (this.getField("BalanceForward").value) - (this.getField("Amt1").value) + (this.getField("Dep1").value);

if (total != "NaN") {

    event.value = total;

}

else {event.value = "";}


Acrobate du PDF, InDesigner et Photoshopographe
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
Guest
Jan 18, 2018 Jan 18, 2018

JR,

Thanks so much! This is much closer than what I was trying.

This script works on the first line of the form and the beginning balance (BalanceForward field) is auto-populating on all lines of the form. Is it possible to show a zero balance or blank until a check or deposit is entered? 

I copied the script you provided (example below), simply changing the field names for remaining lines. It works, but again ideally I don't want the balance field to populate unless there is an entry made.

var total = (this.getField("Bal1").value) - (this.getField("Amt2").value) + (this.getField("Dep2").value);

if (total != "NaN" || total != Infinity  || total != -Infinity) {

    event.value = total;

}

else {event.value = "";}

Thanks again. I truly appreciate the help.

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
Community Expert ,
Jan 19, 2018 Jan 19, 2018
LATEST

Try this one:

if ((this.getField("BalanceForward").value != "") && (this.getField("Amt1").value != "") && (this.getField("Dep1").value != "")) {

    var total = (this.getField("BalanceForward").value) - (this.getField("Amt1").value) + (this.getField("Dep1").value); 

    if (total != "NaN") { 

        event.value = total; 

    } 

    else {event.value = "";}

}


Acrobate du PDF, InDesigner et Photoshopographe
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