Create field driven calculation with exponents

New Here ,
Sep 24, 2017

Copy link to clipboard

Copied

I'm very, very new to JS: I want 2 fields in a PDF (Calc B & C) to auto-populate with calculated data based on another (Input A), or remain blank if there isn't any value.

My problem:

Input A = 10

Calc B = ((("Input A" * 1000)^(2/3))*10.1)/10000

Calc C = ((("Input A")^0.75) * 70) + 30

I've tried so many combinations of calculations and it either doesn't do anything or give me any number of syntax errors

I though that the entire field entered as:

((Math.pow(this.getField("Input A").value*1000, (2/3)))*10.1)/10000

would work but it doesn't do anything! Please help! Is there a way to create an empty "Calc B" if "Input A" is empty?

Thanks in advance!

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Add "event.value = " before your code, like this:

event.value = ((Math.pow(this.getField("Input A").value*1000, (2/3)))*10.1)/10000;

(Note that I didn't check the validity or syntax of your code, but that's what was missing from it to assign the value to the field)

TOPICS
Acrobat SDK and JavaScript

Views

302

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

Create field driven calculation with exponents

New Here ,
Sep 24, 2017

Copy link to clipboard

Copied

I'm very, very new to JS: I want 2 fields in a PDF (Calc B & C) to auto-populate with calculated data based on another (Input A), or remain blank if there isn't any value.

My problem:

Input A = 10

Calc B = ((("Input A" * 1000)^(2/3))*10.1)/10000

Calc C = ((("Input A")^0.75) * 70) + 30

I've tried so many combinations of calculations and it either doesn't do anything or give me any number of syntax errors

I though that the entire field entered as:

((Math.pow(this.getField("Input A").value*1000, (2/3)))*10.1)/10000

would work but it doesn't do anything! Please help! Is there a way to create an empty "Calc B" if "Input A" is empty?

Thanks in advance!

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Add "event.value = " before your code, like this:

event.value = ((Math.pow(this.getField("Input A").value*1000, (2/3)))*10.1)/10000;

(Note that I didn't check the validity or syntax of your code, but that's what was missing from it to assign the value to the field)

TOPICS
Acrobat SDK and JavaScript

Views

303

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
Sep 24, 2017 0
Most Valuable Participant ,
Sep 25, 2017

Copy link to clipboard

Copied

Add "event.value = " before your code, like this:

event.value = ((Math.pow(this.getField("Input A").value*1000, (2/3)))*10.1)/10000;

(Note that I didn't check the validity or syntax of your code, but that's what was missing from it to assign the value to the field)

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
Reply
Loading...
Sep 25, 2017 0
Adobe Community Professional ,
Sep 25, 2017

Copy link to clipboard

Copied

You need to use the "Custom JavaScript calculation" option. JavaScript does not use the "^" for exponentiation, instead it uses the Math.pow() method.

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
Reply
Loading...
Sep 25, 2017 0