Skip to main content
Participant
June 29, 2020
Answered

Form adding 1 to calculated field

  • June 29, 2020
  • 2 replies
  • 1165 views

Hi,

I have a purchase order form which includes a quantity field (QtyRow1), a Unit Price field (Unit PriceRow1) and an extended total field (Extended AmountRow1). I have added script that I found in the forum to the custom calculation field to return a blank if zero . However, although I get a blank correctly when it's zero,  it adds one to the total when there's a calculation, and I can't see where the script is telling it to do that. 

This is the script that I have:

 

//Custom Calculate script
(function (){

//Get field values as numbers and calculate sum
var v1=+getField("QtyRow1").value;
var v2=+getField("Unit PriceRow1").value;
var sum=v1+v2;

//Set this Field's value
if (getField("Unit PriceRow1").valueAsString===""){
event.value="";
}else{
event.value=sum;
}

})();

 

I am using Acrobat Pro DC. Thanks in advance for any help that you can provide.

    This topic has been closed for replies.
    Correct answer try67

    Shouldn't you multiply the two values, not add them?


    Change:

    var sum=v1+v2;

    To:

    var sum=v1*v2;

    2 replies

    Bernd Alheit
    Community Expert
    Community Expert
    July 7, 2020

    Why does you use the sum of quantity and unit price?

    try67
    Community Expert
    Community Expert
    June 29, 2020

    That's very strange... Are the other fields calculated, too?  If so, check the fields calculation order.

    If that's not the case, please share the actual file with us.

     

    Participant
    July 7, 2020

    The other fields are not calculations. Here is the link to the form:

    https://www.dropbox.com/s/jb0kyra8nmucaqt/TOL%20Purchase%20order%20test_zero.pdf?dl=0

    I just tested it again, and the calculation does not seem to be working at all. It's supposed to multiply the Qty by the Unit Price to get a sum, otherwise return zero.

    Let me know if the link doesn't work. This is the first time I've tried to share something like this.

    Thanks.

    try67
    Community Expert
    Community Expert
    July 7, 2020

    Shouldn't you multiply the two values, not add them?