Skip to main content
ericae37044028
Participating Frequently
June 22, 2018
Answered

Javascript Calculations not working for me.

  • June 22, 2018
  • 3 replies
  • 1838 views

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?

This topic has been closed for replies.
Correct answer try67

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.

3 replies

BarlaeDC
Community Expert
Community Expert
June 25, 2018

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

ericae37044028
Participating Frequently
June 25, 2018

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

Bernd Alheit
Community Expert
Community Expert
June 26, 2018

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

Bernd Alheit
Community Expert
Community Expert
June 22, 2018

Check the field calculation order.

ericae37044028
Participating Frequently
June 22, 2018

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

try67
Community Expert
Community Expert
June 22, 2018

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

BarlaeDC
Community Expert
Community Expert
June 22, 2018

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

ericae37044028
Participating Frequently
June 22, 2018

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