Need help with javascript calculation so there's no error pop-up message.

New Here ,
Sep 20, 2022 Sep 20, 2022

Copy link to clipboard

Copied

Hi, I don't really know javascript, but I had someone help me write some script and then used that to write others. I write the pdf in Foxit PDF editor, and then we use this form in Adobe.

 

I'm stuck, because, although the calculation works properly, we get an error pop up that won't let us use this interactive form. The issue is in the form field box named "Estimated Payments" (page 25). We use the first page to fill out our contracts and then the rest of the contract gets auto-filled. The javascrpt written is in the Calculate tab under Custom calculation script and is as follows:

 

var factor = this.getField("Factor Rate").value;
var purchase_price = this.getField("Purchase Price").value;
var pull = this.getField("Pulling Amount").value;{
event.value = purchase_price * factor / pull;

}

The issue is that as soon as I try to enter something in any field and move to the next field I get a pop-up message that says "The value entered does not match the format of the field [Estimated Payments]." It then takes me straight to the page with that field. The only way this does not pop up is if I put an amount in the field "Purchase Price". Am I writing something wrong? Or is it that it does not want that box empty. The fields that this box is getting the values to calculate from, are not filled in until we make the contract as the values vary. How do I write a script that will work and we won't get the pop-up? I'm thinking that maybe I need a script saying that if there is a value in the field "Puchase Price" then do the calculation, and if not then leave blank. How would I write that?

TOPICS
How to , JavaScript , PDF forms

Views

27

Likes

Translate

Translate

Report

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 , Sep 20, 2022 Sep 20, 2022

That happen when you try to divide with 0, check that variable pull is not empty, something like this:

var factor = this.getField("Factor Rate").value;
var purchase_price = this.getField("Purchase Price").value;
var pull = this.getField("Pulling Amount").value;
if(pull == "")
event.value = "";
else
event.value = purchase_price * factor / pull;

Likes

Translate

Translate
Community Expert ,
Sep 20, 2022 Sep 20, 2022

Copy link to clipboard

Copied

That happen when you try to divide with 0, check that variable pull is not empty, something like this:

var factor = this.getField("Factor Rate").value;
var purchase_price = this.getField("Purchase Price").value;
var pull = this.getField("Pulling Amount").value;
if(pull == "")
event.value = "";
else
event.value = purchase_price * factor / pull;

Likes

Translate

Translate

Report

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
New Here ,
Sep 20, 2022 Sep 20, 2022

Copy link to clipboard

Copied

LATEST

Thank you!!! You are amazing at this!!

Likes

Translate

Translate

Report

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