Skip to main content
Participant
November 29, 2017
Answered

I am attempting to develop a pdf form that will perform calculations based on user input. I have been able to accomplish some of the more basic calculations, such as multiplication, but am having trouble when it comes to performing some of the more c

  • November 29, 2017
  • 1 reply
  • 1418 views

I have attempted to break my equation down and only perform the power or square root functions and the text box does not respond. So i have narrowed it down to the fact that neither of these math functions are working for me.

This topic has been closed for replies.
Correct answer George_Johnson

The custom calculation script for the field could be something like:

// Custom calculation script for text field

(function () {

    // Get the field values, as numbers

    var v1 = +getField("UserEntry1").value;

    var v2 = +getField("UserEntry2").value;

    var v3 = +getField("UserEntry3").value;

    // Perform the calculation and set this field's value

    event.value = 29.84 * v1 * Math.sqrt(v2) * Math.pow(v3, 2);

{)();

When troubleshooting JavaScript, it is helpful to check the JavaScript console (Ctrl+J) for errors.

1 reply

jcmolinAuthor
Participant
November 29, 2017

I believe my problem statement was cut off. Here is it: I am attempting to develop a pdf form that will perform calculations based on user input. I have been able to accomplish some of the more basic calculations, such as multiplications, but am having trouble when it comes to performing some of the more complex calculations. I am attempting to perform the following calculation (29.84*UserEntry1*sqrt(UserEntry2)*(UserEntry3^2). I have read several forums and I understand that adobe pro uses JavaScript, so I have attempted to incorporate commands such as Math.pow("UserEntry3",2). I have also tried Math.pow(this.getField("UserEntry3").value*1,2). In a similar fashion I have attempted to use the Math.sqrt function with no luck. I do not receive an error with my equation. The box simply is unresponsive to any user input values. Any ideas as to what could be the issue?

George_JohnsonCorrect answer
Inspiring
November 30, 2017

The custom calculation script for the field could be something like:

// Custom calculation script for text field

(function () {

    // Get the field values, as numbers

    var v1 = +getField("UserEntry1").value;

    var v2 = +getField("UserEntry2").value;

    var v3 = +getField("UserEntry3").value;

    // Perform the calculation and set this field's value

    event.value = 29.84 * v1 * Math.sqrt(v2) * Math.pow(v3, 2);

{)();

When troubleshooting JavaScript, it is helpful to check the JavaScript console (Ctrl+J) for errors.

jcmolinAuthor
Participant
December 1, 2017

Thank you! That worked great! so if i would want to follow up with the following calculation: AutoCalc1*((UserEntry2 - 20)/(UserEntry2 - UserEntry3))^0.54).

Shouldn't the following script work:

var v1 = +getField("AutoCalc1").value;

var v2 = +getField("UserEntry2").value;

var v3 = +getField("UserEntry3").value;

event.value = v1 * Math.pow(((v2 - 20)/(v2 - v3)), 0.54);

I am being prompted with a  window that says the value entered does not match the format of the field. Don't quite understand the issue.