Copy link to clipboard
Copied
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.
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 (Ct
...Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
You need to make sure that the result of v2-v3 is not zero, as that would mean division by zero, which is not allowed.
Copy link to clipboard
Copied
Change the format of the field to "None" and observe what appears. It could be "NaN", a number expressed in scientific notation, "Infinity", or "-Infinity". You can then adjust your script to handle the result in an appropriate manner.