Some Form fields not calculating - getting Null errors in JS...Dont know what to do at this point
- April 23, 2024
- 4 replies
- 638 views
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....
