• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

Javascript Calculations not working for me.

New Here ,
Jun 22, 2018 Jun 22, 2018

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?

TOPICS
Acrobat SDK and JavaScript

Views

374

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 , Jun 26, 2018 Jun 26, 2018

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.

Likes

Translate

Translate
Community Expert ,
Jun 22, 2018 Jun 22, 2018

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

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 ,
Jun 22, 2018 Jun 22, 2018

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

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
Community Expert ,
Jun 22, 2018 Jun 22, 2018

Copy link to clipboard

Copied

Check the field calculation order.

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 ,
Jun 22, 2018 Jun 22, 2018

Copy link to clipboard

Copied

I've done that as well but still not working.

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
Community Expert ,
Jun 22, 2018 Jun 22, 2018

Copy link to clipboard

Copied

Check the JS Console (Ctrl+J) for error messages.

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 ,
Jun 22, 2018 Jun 22, 2018

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

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
Community Expert ,
Jun 22, 2018 Jun 22, 2018

Copy link to clipboard

Copied

That means the value of one of your fields is not actually a number.

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
LEGEND ,
Jun 22, 2018 Jun 22, 2018

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.

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
Community Expert ,
Jun 22, 2018 Jun 22, 2018

Copy link to clipboard

Copied

The result of division by zero is Infinity, actually.

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
LEGEND ,
Jun 23, 2018 Jun 23, 2018

Copy link to clipboard

Copied

Well... it depends what you are dividing.

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
Community Expert ,
Jun 23, 2018 Jun 23, 2018

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.

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
Community Expert ,
Jun 25, 2018 Jun 25, 2018

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

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 ,
Jun 25, 2018 Jun 25, 2018

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.

Consultation Fee Form.pdf - Google Drive

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
Community Expert ,
Jun 25, 2018 Jun 25, 2018

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

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
Community Expert ,
Jun 26, 2018 Jun 26, 2018

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.

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 ,
Jun 26, 2018 Jun 26, 2018

Copy link to clipboard

Copied

LATEST

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.

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