Copy link to clipboard
Copied
I have set up form fields to automatically populate calculations once numbers are entered into some of the other fields on the form. Everything is working except for the last formula:
var v12 = getField("Out of Pocket Investment").value;
var v10 = getField("Opt 3 Monthly Payment").value;
var v11 = getField("Opt 3 # of Months").value;
event.value = (v12 - v10 * v11) * .75 ;
Any thoughts as to why this is not working for me?
1 Correct answer
You created the fields in InDesign. Don't.
You'll notice that the fields are not identifiable by a script in Acrobat. You need to work with form fields either exclusively in ID or in Acrobat, from my experience.
Copy link to clipboard
Copied
Hi,
it looks like you are missing the ‘this’ statement before the getField function. So you code should look like this
var v12 = this.getField(“Out of Pocket Investment”).value;
if you add that to all lines, it should work.
Hope this helps
Malcolm
Copy link to clipboard
Copied
I tried that, but it's still not working for me.
From: BarlaeDC <forums_noreply@adobe.com>
To: Erica Egner <ericaegner@yahoo.com>
Sent: Friday, June 22, 2018 12:19 PM
Subject: Javascript Calculations not working for me.
Javascript Calculations not working for me. created by BarlaeDC in JavaScript - View the full discussionHi, it looks like you are missing the ‘this’ statement before the getField function. So you code should look like this var v12 = this.getField(“Out of Pocket Investment”).value; if you add that to all lines, it should work. Hope this helps Malcolm If the reply above answers your question, please take a moment to mark this answer as correct by visiting: https://forums.adobe.com/message/10461929#10461929 and clicking ‘Correct’ below the answer Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: Please note that the Adobe Forums do not accept email attachments. If you want to embed an image in your message please visit the thread in the forum and click the camera icon: https://forums.adobe.com/message/10461929#10461929 To unsubscribe from this thread, please visit the message page at , click "Following" at the top right, & "Stop Following" Start a new discussion in JavaScript by email or at Adobe Community For more information about maintaining your forum email notifications please go to https://forums.adobe.com/thread/1516624. This email was sent by Adobe Community because you are a registered user. You may unsubscribe instantly from Adobe Community, or adjust email frequency in your email preferences |
Copy link to clipboard
Copied
Check the field calculation order.
Copy link to clipboard
Copied
I've done that as well but still not working.
Copy link to clipboard
Copied
Check the JS Console (Ctrl+J) for error messages.
Copy link to clipboard
Copied
I’ve done that as well. I keep getting ‘NaN’ but don’t know how to fix that.
Sent from Yahoo Mail for iPhone
Copy link to clipboard
Copied
That means the value of one of your fields is not actually a number.
Copy link to clipboard
Copied
NaN is the result of an impossible calculations like dividing by zero. Dividing by a field that isn't filled in yet is a classic cause. If that doesn't help, share the file and post a URL. Remember it's public.
Copy link to clipboard
Copied
The result of division by zero is Infinity, actually.
Copy link to clipboard
Copied
Well... it depends what you are dividing.
Copy link to clipboard
Copied
True... If you divide 0 by 0 (or NaN by 0) the result will be NaN. Anything else will be Infinity.
Copy link to clipboard
Copied
HI,
The best plan is just to check for numbers before you calculation, something like
var v12 = getField("Out of Pocket Investment").value;
var v10 = getField("Opt 3 Monthly Payment").value;
var v11 = getField("Opt 3 # of Months").value;
if ( isNaN ( parseInt( v10, 10)) || isNaN (parseInt ( v11, 10)) || isNaN (parseInt ( v12, 10)))
{
console.println ( "error - one or more fields is blank or has non number entered");
event.value = 0;
}
else
{
event.value = (v12 - v10 * v11) * .75 ;
}
This way the calculation will only run when you have 3 numbers for it to run on.
Hope this helps
Malcolm
Copy link to clipboard
Copied
Thanks for the suggestion. I still haven't had any luck. I've copied a version of my form into Google Docs. You should be able to download from this link and see the calculations for yourself.
Copy link to clipboard
Copied
Check the names of the fields.
Some fields have spaces at the end of the name. Like:
Opt 3 Monthly Payment
Opt 3 # of Months
Copy link to clipboard
Copied
You created the fields in InDesign. Don't.
You'll notice that the fields are not identifiable by a script in Acrobat. You need to work with form fields either exclusively in ID or in Acrobat, from my experience.
Copy link to clipboard
Copied
Thank you so much! I can't believe that's all it was the entire time. I just rebuilt all the form fields in Acrobat and it works beautifully.