These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Making a field less than zero show zero

sdoud
Registered: May 11 2010
Posts: 9
Answered

I have an employee expense form I created in Acrobat (Pro 9) as a form. I have four fields -

Total_Expenses (calculated from a couple of subtotal fields elsewhere in the form)
Cash_Advance (text field the employee can enter a value into
Due_Employee
Due_Bank

I want to use either a calculation or validation javascript to populate the last two. If Total_Expenses is greater than Cash_Advance, then Due_Employee will show the difference and Due_Bank will show 0. If Cash_Advance is greater than Total_Expenses, then Due_Employee will be 0 and Due_Bank will show the difference. I can't seem to get it to work either way.

My Product Information:
Acrobat Pro 9.3.1, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2399
Place this code as Due_Employee's custom calculation script:
TotalExpenses = this.getField("Total_Expenses").value;CashAdvance = this.getField("Cash_Advance").value; if (TotalExpenses>CashAdvance) {this.getField("Due_Bank").value = 0;event.value = TotalExpenses-CashAdvance;} else if (CashAdvance>TotalExpenses) {this.getField("Due_Bank").value = TotalExpenses-CashAdvance;event.value = 0;}

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

sdoud
Registered: May 11 2010
Posts: 9
First - thanks for the response, and the code!! Works great - almost! :-)

I took the liberty of flipping the last calculation (TotalExpenses-CashAdvance) the other way around (CashAdvance-TotalExpenses). I didn't mention it in my post, so my fault - but I thought it looked better if the amount always showed as a positive number. Hope that makes sense. Like I said, lack of clarity on my part - but, with that small change, it's just what I needed. Thanks!!!!!!
try67
Expert
Registered: Oct 30 2008
Posts: 2399
Be aware that if the two values are the same, nothing will happen using this code.
To take care of that, you can add another else {} block at the end, like so:

} else { }

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

sdoud
Registered: May 11 2010
Posts: 9
I will do that, thanks. In our case, that doesn't matter since the field starts at zero and the result of the fields being the same is also that value. Doesn't hurt to be clean though, right? Thanks again!