Copy link to clipboard
Copied
Hi All, I have a calculated field form where some of the fields calculate fine and then others do not... I am getting Null errors in JS console. I am not a JS expert and had ChatGPT4 check my code. I have tried everything form setting calc order to rebuilding the form. Errors and issues are the same....
I am happy to share the enitre form if anyone can help... i have done the same thing with a different form that had slightly less caluclating and it worked fine.
this is a section of code that is not calculating...
// Retrieve values from the form fields and convert them to numbers
var field1 = Number(this.getField("ContribCredit2").value);
var field2 = Number(this.getField("ReducPct").value);
var field3 = Number(this.getField("AutoEnrollCredit2").value);
var field4 = Number(this.getField("StartCredit2").value);
// Check for NaN values and handle them
if (isNaN(field1) || isNaN(field2) || isNaN(field3) || isNaN(field4)) {
console.error("One or more fields contain non-numeric data.");
event.value = "Error: Invalid input."; // Display error message in the result field
} else {
// Calculate the result by applying the formula and round the final result
var result = Math.round((field1 * field2) + field3 + field4);
// Set the calculated result as the value of the event (usually the result field)
event.value = result;
}
any help is appreciated....
Copy link to clipboard
Copied
Null error means you have wrong field names in your script, for example in script in field "Year1-2" change: "ReducPct" to "ReducPCT" there are also wrong names in scripts in fields "Year 2-2" and "75Pct".
Btw, 'console.error' is not usable in acrobat, instead use console.println().
Copy link to clipboard
Copied
In addition to the correct remarks by @Nesa Nurani , you need to remove such lines from your code:
// Attach event to field
var field = this.getField("ReducPCT");
field.setAction("OnBlur", "calculatePDF();");
You probably got this code off of ChatGPT, but it's not how you should use it. This code only needs to be executed once. Including it in the actual calculation script will result in errors and prevent it from working properly.
Copy link to clipboard
Copied
Thanks i will try these fixes and see how it goes. I truly appreciate the help...
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Check the JS Console. There are errors in your code that could prevent it from executing correctly.