Copy link to clipboard
Copied
Hello,
I'm working on a fillable pdf budget sheet. I want to add in formulas to calculate percentages. I found the code below to remove my "Warning: Javascript Window" issue from a previous forum article. I also want to add in the equation "AmountRentandFees/(TotAnnInc/12)". It works as a stand alone equation but it does not work with the code below. Is there a way that I can use both?? I'm not JavaScript savvy. Any simple ideas people may have would be greatly appreciated! Thanks!
Pat
Remove warning:JavaScript window message from dialog (JavaScript)
var dialogTrust = app.trustedFunction(function(){app.beginPriv();var data = { description: { name: "Test Dialog", elements: [{ name: "Hello World", type: "static_text", },{ type: "ok", },] } }; app.execDialog(data);app.endPriv();});
1 Correct answer
You got a bit off track with the custom dialog stuff since it is not at all related to your problem. You have to fix the script as Bernd suggested so that error isn't generated. The custom calculation script for the field could be something like:
// Custom Calculation script
(function () {
// Get the field values, as numbers
var v1 = +getField("AmountRentandFees").value;
var v2 = +getField("TotAnnInc").value;
// Perform calculation and set this field value
if (v2 !== 0) {
eve
...Copy link to clipboard
Copied
You're going to have to provide more information. It's not clear to me what the formula has to do with the custom dialog. Did you want to include fillable fields on the dialog and calculate a value based on what the user enetered, or have the dialog display a calculated value based on the contents of fields on the form, or something else?
Copy link to clipboard
Copied
Hi George!
Much thanks for your reply! Right now, I have it set up so that someone will enter a value into a text box ("TotAnnInc") that totals their annual pre-deduction pay (gross income). The formula then takes what the tenant is paying in rent ("AmountRentandFees") and calculates their housing ratio (a percentage). I have this part working just great. However, whenever I save the pdf and start using it, it sends me the "Warning: Javascript Window" alert repeatedly. This alert makes it cumbersome to enter other values into the pdf until I enter in the total annual income ("TotAnnInc"). I found the above code to silence the "Warning: Javascript Window" but then it won't calculate the housing ratio. Does that make sense? Any wisdom you have to share would be greatly appreciated.
Thanks,
pat
Copy link to clipboard
Copied
You got a bit off track with the custom dialog stuff since it is not at all related to your problem. You have to fix the script as Bernd suggested so that error isn't generated. The custom calculation script for the field could be something like:
// Custom Calculation script
(function () {
// Get the field values, as numbers
var v1 = +getField("AmountRentandFees").value;
var v2 = +getField("TotAnnInc").value;
// Perform calculation and set this field value
if (v2 !== 0) {
event.value = util.printf("%.2f", v1 /( v2 / 12)); // Round result to nearest cent
} else {
event.value = ""; // Blank this field if annual income is blank or zero
}
})();
Copy link to clipboard
Copied
Thank you George! This is super helpful! It did the trick. I appreciate all of your help.
Copy link to clipboard
Copied
Do avoid division by zero you must Javascript for the calculation.

