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

Adobe Forms - Simple IF Statement

Community Beginner ,
Dec 18, 2018 Dec 18, 2018

Copy link to clipboard

Copied

Hi there - forgive the complete noob question, hope you can help.

SecureDep = Security Deposit
RentPW = Rent Per Week

RentPCM = Rent Per Calendar Month (Calculated at RentPW*52/12)
ContractLength = Contract Length in months

I'm trying to populate the Balance to Pay field.

Security Deposit can either be 2 weeks or 6 weeks. The Balance to Pay will change depending on this single field.

If the Security Deposit is 2 weeks, then the Balance to Pay will be ContractLength * RentPCM

If the Security Deposit is 6 weeks, then Balance to Pay will be RentPCM+(RentPW*4)

So....unsuccessfully I have tried:

IF(SecureDep/2=RentPW, ContractLength*RentPCM, RentPCM+RentPW*4) This didn't work in Simplified Field Notation

Can someone please kindy help me with this? I don't know any Javascript and already tried 2 hours to find a solution, thank you so much!

TOPICS
Acrobat SDK and JavaScript , Windows

Views

314

Likes

Translate

Translate

Report

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 , Dec 18, 2018 Dec 18, 2018

The custom calculation script could be something like this:

(function () {

    // Get the input field values, as numbers

    // Blank fields will equal 0 (zero)

    var SecureDep = +getField("SecureDep").value;

    var RentPW = +getField("RentPW").value;

    var RentPCM = +getField("RentPCM").value;

    var ContractLength = +getField("ContractLength").value;

    // If any of the inputs are zero or less, set this field value to blank

    if (SecureDep <= 0 || RentPW <= 0 || Rent PCM <= 0 || ContractLength

...

Likes

Translate

Translate
Community Expert ,
Dec 18, 2018 Dec 18, 2018

Copy link to clipboard

Copied

Here's an article on simple calculations:

https://acrobatusers.com/tutorials/how-to-do-not-so-simple-form-calculations

Here's one on using an "if' statement in a calculation:

https://acrobatusers.com/tutorials/conditional-execution

And here's a site on everything you want to know about PDF JavaScript calculations:

Calculating field values and more

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

Translate

Translate

Report

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 Beginner ,
Dec 18, 2018 Dec 18, 2018

Copy link to clipboard

Copied

Thanks Thom,

I've just read your articles, but I already had spent hours trying to understand Javascript, I'm not as smart as you

I'm just trying to get help with the code, I'm trying many things, none of which seem to work. Can you please help?

Likes

Translate

Translate

Report

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 ,
Dec 18, 2018 Dec 18, 2018

Copy link to clipboard

Copied

The custom calculation script could be something like this:

(function () {

    // Get the input field values, as numbers

    // Blank fields will equal 0 (zero)

    var SecureDep = +getField("SecureDep").value;

    var RentPW = +getField("RentPW").value;

    var RentPCM = +getField("RentPCM").value;

    var ContractLength = +getField("ContractLength").value;

    // If any of the inputs are zero or less, set this field value to blank

    if (SecureDep <= 0 || RentPW <= 0 || Rent PCM <= 0 || ContractLength <= 0) {

        event.value = "";

    } else {

        // Calculate this field's value

        if (SecureDep / 2 == RentPW) {

            event.value = ContractLength * RentPCM;

        } else {

            event.value = RentPCM + 4 * RentPW;

        }

    }

})();

It will be important that the field calculation order is correct. If you don't know how to confirm that it is, you can do a search and/or post again.

Likes

Translate

Translate

Report

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 Beginner ,
Dec 19, 2018 Dec 19, 2018

Copy link to clipboard

Copied

Hi George,

Thank you! I appreciate the time you spent to help.

I am getting an error if I try this:

SyntaxError: missing ) after condition 21: at line 22

I am attaching a screenshot of the form, basically the only fields that are manually inputted are ContractLength (length of contract in months) RentPW (rent per week) and SecureDep (security deposit) - the idea is that the form will self-populate itself based on the three manual entries.

Adobe Form Calculations.jpg

Just in case you need to see the actual form it is here: Dropbox - Test Booking Form.pdf

Thank you so much for taking the time to help

Likes

Translate

Translate

Report

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 ,
Dec 19, 2018 Dec 19, 2018

Copy link to clipboard

Copied

The field "Group 1" doesn't exist in the form.

Likes

Translate

Translate

Report

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 Beginner ,
Dec 19, 2018 Dec 19, 2018

Copy link to clipboard

Copied

Hi, I don't understand, why is that needed? I changed the name of Group 1 to ​PaymentType

Likes

Translate

Translate

Report

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 ,
Dec 19, 2018 Dec 19, 2018

Copy link to clipboard

Copied

In your code you use this:

this.getField("Group 1")

Likes

Translate

Translate

Report

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 Beginner ,
Dec 19, 2018 Dec 19, 2018

Copy link to clipboard

Copied

Sorry - I was trying something! I was trying to get the radio button to auto-populate the SecureDep field and then have that impact the balance to pay. A wonderful idea, but for someone like me with zero javascript knowledge a bad move!

Here is the form which removes the Group 1 field and removes code: Dropbox - Test Booking Form.pdf

I still have errors for George's code tho

Thank you to anyone who can help

Likes

Translate

Translate

Report

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 Beginner ,
Dec 19, 2018 Dec 19, 2018

Copy link to clipboard

Copied

To confirm, a user inputs:

Length of Stay = "Duration"

Rent per week = "RentPW"

Security Deposit = "SecureDep"

IF the security deposit is 2 weeks, then the balance to pay "Balance" field is auto-populated to RentPCM+(RentPW *  4), anything else the "Balance" field auto-populates to Duration * RentPCM.

In an ideal world, the radio button will auto-populate the SecureDep field, but I may attempt that slightly later

Likes

Translate

Translate

Report

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 ,
Dec 19, 2018 Dec 19, 2018

Copy link to clipboard

Copied

What errors did you get?

Likes

Translate

Translate

Report

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 Beginner ,
Dec 19, 2018 Dec 19, 2018

Copy link to clipboard

Copied

SyntaxError: missing ) after condition 21: at line 22

Likes

Translate

Translate

Report

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 ,
Dec 19, 2018 Dec 19, 2018

Copy link to clipboard

Copied

Post your full code, please.

Likes

Translate

Translate

Report

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 Beginner ,
Dec 19, 2018 Dec 19, 2018

Copy link to clipboard

Copied

It is posted above and I've attached the form as well

Likes

Translate

Translate

Report

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 ,
Dec 19, 2018 Dec 19, 2018

Copy link to clipboard

Copied

I thought you changed it since then. Yes, Bernd's suggestion will solve this issue.

Likes

Translate

Translate

Report

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 ,
Dec 19, 2018 Dec 19, 2018

Copy link to clipboard

Copied

When you get the error at adding the code remove the space in:

Rent PCM

Likes

Translate

Translate

Report

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 Beginner ,
Dec 19, 2018 Dec 19, 2018

Copy link to clipboard

Copied

Thanks Bernd, I'll try that!

Likes

Translate

Translate

Report

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 Beginner ,
Dec 19, 2018 Dec 19, 2018

Copy link to clipboard

Copied

LATEST

Thanks that DID the trick!!

After I get the error, I have to remove the space

Now if I can only figure out how the radio buttons work so the SecureDep field changes dependent on the selection, I'm golden

Likes

Translate

Translate

Report

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