Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Some Form fields not calculating - getting Null errors in JS...Dont know what to do at this point

New Here ,
Apr 23, 2024 Apr 23, 2024

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....

 

 

 

 

 

TOPICS
Modern Acrobat , PDF , PDF forms
493
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 23, 2024 Apr 23, 2024

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().

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 23, 2024 Apr 23, 2024

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 23, 2024 Apr 23, 2024

Thanks i will try these fixes and see how it goes. I truly appreciate the help...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 23, 2024 Apr 23, 2024

Hi - so i made the changes as suggested - but in my form the items under each year are still not showing up....any further suggestions? 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 23, 2024 Apr 23, 2024
LATEST

Check the JS Console. There are errors in your code that could prevent it from executing correctly.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines