Skip to main content
Known Participant
December 18, 2018
Answered

Adobe Forms - Simple IF Statement

  • December 18, 2018
  • 2 replies
  • 1246 views

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!

This topic has been closed for replies.
Correct answer George_Johnson

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.

2 replies

George_JohnsonCorrect answer
Inspiring
December 19, 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 <= 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.

Known Participant
December 19, 2018

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.

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

Bernd Alheit
Community Expert
Community Expert
December 19, 2018

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

Thom Parker
Community Expert
Community Expert
December 18, 2018

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 PDFScriptingUse the Acrobat JavaScript Reference early and often
Known Participant
December 18, 2018

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?