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

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

New Here ,
Feb 28, 2017 Feb 28, 2017

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

TOPICS
Acrobat SDK and JavaScript , Windows
2.7K
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

correct answers 1 Correct answer

LEGEND , Feb 28, 2017 Feb 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) {

        eve

...
Translate
LEGEND ,
Feb 28, 2017 Feb 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?

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 ,
Feb 28, 2017 Feb 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

PDF1.pngPDF2.png

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
LEGEND ,
Feb 28, 2017 Feb 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

    }

})();

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 ,
Feb 28, 2017 Feb 28, 2017
LATEST

Thank you George! This is super helpful! It did the trick. I appreciate all of your 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
Community Expert ,
Feb 28, 2017 Feb 28, 2017

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

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