Add the values of checkboxes on an Adobe Form
I am trying to write a script that adds the values of 11 different fields on a PDF form where 11 checkboxes representing the 11 fields are checked and adds 200 to the final amount. When the checkbox is not checked, I do not add the value representing that checkbox. I have written the script below but it only displays $200.
// Define an array with the names of the 11 checkboxes and the corresponding fields
var checkboxFieldNames = [
{ checkbox: "AGT", field: "150.00" },
{ checkbox: "OneYA", field: "75.00" },
{ checkbox: "2YA", field: "112.00" },
{ checkbox: "CGT", field: "75.00" },
{ checkbox: "GTLateFee", field: "10.00" },
{ checkbox: "ChapterLateFee", field: "20.00" },
{ checkbox: "NHBF", field: "100.00" },
{ checkbox: "EFCB500", field: "500.00" },
{ checkbox: "EFCB250", field: "250.00" },
{ checkbox: "EFCB100", field: "100.00" },
{ checkbox: "EFCB50", field: "50.00" }
];
var total = 0;
// Loop through the checkboxes and add their corresponding field values
for (var i = 0; i < checkboxFieldNames.length; i++) {
var checkboxName = checkboxFieldNames[i].checkbox;
var fieldName = checkboxFieldNames[i].field;
if (this.getField(checkboxName).isBoxChecked(0)) {
var fieldValue = parseFloat(this.getField(fieldName).value) || 0;
total += fieldValue;
}
}
// Add 200 to the total
total += 200;
// Set the total value in a result field
this.getField("TAD").value = total;
