Skip to main content
patrickn43659930
Participant
February 28, 2017
Answered

How can I both remove a warning: JavaScript window message and maintain a formula?

  • February 28, 2017
  • 2 replies
  • 2856 views

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();
});

This topic has been closed for replies.
Correct answer George_Johnson

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

    }

})();

2 replies

Bernd Alheit
Community Expert
Community Expert
February 28, 2017

Do avoid division by zero you must Javascript for the calculation.

Inspiring
February 28, 2017

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?

patrickn43659930
Participant
February 28, 2017

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

George_JohnsonCorrect answer
Inspiring
February 28, 2017

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

    }

})();