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

make FieldName/Fieldname (divide by) HELP

Bort
Registered: Feb 13 2011
Posts: 5

Hi,
 
I'm trying to build a form for my lanscaping business. Here is the form:
http://theoutcasts.net/bort/landscaping_wrtbl1.pdf
(it's set up for addition right now to show another confusion I have)
 
What I'm trying to get it to do is divide the "Number of Visits" by the "Balance" and display that result in the "Annual" field.
 
It will do any other arithmetic operation OTHER than divide. As soon as I have the script make it perform division I get "the value entered does not match the format of the field [Annual]" as described in this thread:
http://acrobatusers.com/forum/forms-acrobat/division-text-field-properties-help
 
The other issue I'm a bit confused on you can cause to happen on the live form I linked above. Place 100 in the "Total" field. Then place 2 in the "Number of Visits" field. Although the script is:
 

var v1 = parseFloat(getField("Balance").value*1);
var v2 = parseFloat(getField("nov").value*1);
&nbsp;<br />
event.value = v1+v2;

(Fields are named accordingly. "Balance" is the balance field name, "nov" is the Number of Visits field name, "Annual" is the annual field name, and "total" is the Total field name.)
 
So, to me, according to the script, it should display the result of 100+2 as 102. But for some reason the addition operation I'm telling it to do is actually subtracting and the result displayed in the Annual field ends up being 98. I'm assuming it's doing that because one of the numbers is a negative integer. But...which one? I'm entering all of the information as positive integers. The only negative I can get it to show is the one that ends up in the Annual field. What the...???
 
How do you fix the positive/negative thing so it performs the math as it should?
 
And [b]how do I write the correct script so that Balance is divided by the value in 'nov'?[/b]
 
I've tried several scripts and have asked for help from several java scripter friends over the last few days and none of us have been successful in getting it to divide or have the result of adding two positive integers end up being a positive number, as it should.
 
I'm praying someone here can help me so I can get this working.

My Product Information:
Acrobat Pro 9.0, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
The problem is you're dividing by zero when the balance field is empty or otherwise evaluates to zero. This is a very common question here and you'll find more help with a search. Use terms like "division, numerator, denominator, zero".

You've set up the balance field so that it's a negative value if the deposit is less than the total. So your script should actually subtract v2. Also, to get the field value as a number, you can just do this:

// Get the field value as a number
var v1 = +getField("Balance").value;




Bort
Registered: Feb 13 2011
Posts: 5
LOL!!!
The whole problem was I was doing the subtraction backwards.
haha..thank you, George!