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

How to do an if then statement on a PDF form

Community Beginner ,
Jun 13, 2016 Jun 13, 2016

I am trying to do an if then statement on a PDF form.

The field is a calculated field A*B=C.  If C<10 then C=10, else C=A*B

How do I write the is Adobe Pro on a PDF form?  I have gone into properties, calculated field and nothing I have tried works.

TOPICS
PDF forms
121.4K
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
1 ACCEPTED SOLUTION
LEGEND ,
Jun 13, 2016 Jun 13, 2016

Each field is a separate object, so if you have 3 fields like "A", "B", and "C" each is a unique object has a unique value. Each field has to be accessed individually, You need to get the value for field "A" in one statement, the value of field "B" in another statement.

var C = this.getField( "A").value * this.getField("B").value;

if( C < 10 ) event.value = 10;

else event.value = C;

You might see it more clearly with some code like:

var A = this.getField( "A").value; // the value of field A;

var B = this.getField( "B").value; // the value of field B;

var C = A * B; // the value of field A times the value of field B;

if( C < 10 ) {

event.value = 10; // value is 10 when product less than 10;

} else [{

event.value = C; // else value is the product;

}

View solution in original post

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 ,
Apr 18, 2017 Apr 18, 2017

If you don't want to change the calculations you can show/hide the fields based on the selection in the radio-button group.

To do that you can use something like this as the MouseUp event of those fields:

this.getField("Field1").display = (event.target.value=="Canine") ? display.visible : display.hidden; // show this field if "Canine" is selected

this.getField("Field2").display = (event.target.value=="Canine") ? display.visible : display.hidden; // show this field if "Canine" is selected

this.getField("Field3").display = (event.target.value=="Canine") ? display.visible : display.hidden; // show this field if "Canine" is selected

this.getField("Field4").display = (event.target.value=="Feline") ? display.visible : display.hidden; // show this field if "Feline" is selected

this.getField("Field5").display = (event.target.value=="Feline") ? display.visible : display.hidden; // show this field if "Feline" is selected

It's not a great solution, but it should work...

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 Beginner ,
Apr 20, 2017 Apr 20, 2017

do I apply these to the radio buttons Field or add this in for each calculated field?

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 ,
Apr 20, 2017 Apr 20, 2017

To the radio-button fields (all of them!).

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 Beginner ,
Apr 20, 2017 Apr 20, 2017

Thank you Try it seems that perhaps the radio button group is not running the JavaScript appropriately (because nothing is happening, maybe a conflict of the other calculations).  It's still putting in  field for Canine calculation even if I have selected a choice for Feline under the radial field.  Perhaps I am entering the code above in the wrong.  I did modify it to include my fields rather than 'Field1', etc.

If I were to modify my calculations what would that look like? 

Thanks again for any 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 ,
Apr 20, 2017 Apr 20, 2017

It might be easier to help you out if you could share the file with us (via Dropbox, Google Drive, Adobe Cloud, etc.)...

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 Beginner ,
Apr 20, 2017 Apr 20, 2017

I wish I could but for confidentiality reasons I can't...I know it makes it tough...could I send over an example with just the portion cut out...I would be able to put in fake fields for reasons of privacy.  Would that work and what's the address I could share it with? I have google drive.

Thank you

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 ,
Apr 21, 2017 Apr 21, 2017

Yes, do that. Share it publicly and post the link to it on the forum.

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 Beginner ,
Apr 21, 2017 Apr 21, 2017

Thank you Try, here's the link to the sample form.  Please let me know if you can help.

SAMPLE PDF Form.pdf - Google Drive

Thank you so much

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 ,
Apr 22, 2017 Apr 22, 2017

I'm not seeing where you placed the code I provided...

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 Beginner ,
Apr 25, 2017 Apr 25, 2017

Ok thank you try, I have added in calculation on the species radio buttons.  It seems as though it works, however I am running into a problem where if I clear the form the zero's from the previous choice stay the same and if the person only enters the BW field then it plugs in doses for the last saved species.  Is there a way to make them hidden until a selection is made on species?

Here's the new link:

SAMPLE PDF Form.pdf - Google Drive

Thank you in advance

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 Beginner ,
Aug 16, 2018 Aug 16, 2018

Did you ever figure this out? I'm having a similar issue.

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 ,
Aug 16, 2018 Aug 16, 2018

Start a new thread with the full details of your question.

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 Beginner ,
May 02, 2017 May 02, 2017

Any luck with this?

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 ,
Mar 01, 2024 Mar 01, 2024
LATEST

How to convert excel formula into pdf form

IMG-20240301-WA0007.jpeg

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 ,
Apr 02, 2020 Apr 02, 2020

I am trying to do an IF statement on a PDF form.

The field is a calculated field on the properties: the ‘Simplified field notation’: BT*7.5 (there is two fields: BT field & Total field) , how do I do so if the field BT is less than 20, multiply by 7.5, but if BT is more than 21, I want to multiply by 5.

Here is my calculation on the Total field with values:

If BT<20 then *7.5, else BT *5

I even tried on ‘Simplified field notation’ and on ‘Custom Calculation Script’. What am I missing?

 

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 ,
Jun 28, 2020 Jun 28, 2020

Can you help me create a javascript for an IF statement.

 

What I am trying to accomplish is this (these are numeric fields: IF FieldA > Field B, display the number in Field B to this field.

 

Your help would be greatly appreciated.

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 ,
Jun 13, 2016 Jun 13, 2016

Each field is a separate object, so if you have 3 fields like "A", "B", and "C" each is a unique object has a unique value. Each field has to be accessed individually, You need to get the value for field "A" in one statement, the value of field "B" in another statement.

var C = this.getField( "A").value * this.getField("B").value;

if( C < 10 ) event.value = 10;

else event.value = C;

You might see it more clearly with some code like:

var A = this.getField( "A").value; // the value of field A;

var B = this.getField( "B").value; // the value of field B;

var C = A * B; // the value of field A times the value of field B;

if( C < 10 ) {

event.value = 10; // value is 10 when product less than 10;

} else {

event.value = C; // else value is the product;

}

You appear to be confusing the parameter  "Value is the _____ of the following fields" and the "Simplified field notation" that are fed into some JavaScript functions that perform the calculation.

A simplified version could be of such a script could be:

function Product(cField1, cField2)

{

/*

purpose: return the product of the value for 2 fields

inputs: names of the two fields

returns: the product of the 2 named fields

*/

var nField1 = this.getField(cField1).value;

var nField2 = this.getField(cField2).value;

return nField1 * nField2;

}

var C = Product("A", "B");

if( C < 10 ) {

event.value = 10; // value is 10 when product less than 10;

} else {

event.value = C; // else value is the product;

}

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

I am trying to do something similar.

I have a field that needs to read either 100, 200 or 300 depending on a value entered in a previous field.

If someone enters 1 in "Field a" then "Field b" needs to read "$100"

If someone enters 2 in "Field a" then "Field b" needs to read "$200"

If someone enters 3 in "Field a" then "Field b" needs to read "$300"

Here was my attempt that I placed in the Custom Calculation Script area for "Field b" and did not work. Can anyone let me know what is wrong? Thank you.

var v1 = this.getField(“Fielda”).value;

if (v1 = 1) {

    event.value = “100”;

}

else if (v1 = 2) {

    event.value = “200”;

}

else if (v1 = 3) {

    event.value = “300”;

}

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

A couple of things:

- Use "==" for the comparisons, not "=".

- Only use straight-quotes ("), not curly ones (“ ”).

- Convert the value of the first field to a number explicitly, like this:

var v1 = Number(this.getField("Fielda").value);

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

- Also, you should add a default value, in case none of the if-statements were true. Add this line to the end of your code:

else event.value = "";

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

WooHoo it works now. Thank you so much try67

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

Hi try67,

I am wondering if you could help me? I am starting out learning java coding and have been reading all posts and trying to get the script to work but have been getting syntax error 3 in the below script:

var f = this.getField("Amount inc GST Row1");

var g = Number(this.getField("GST CodeRow1").value);

if (var g = "GST") {event.value = (f.value / 11)};

else if (var g = "FREE") {event.value = "0"};

else if (var g = "NA") {event.value = "0";

}

Basically, I have 3 text options, GST, FREE and NA.  When I select GST text in my dropdown, it correctly calculates GST from the amount in the "Amount inc GST Row1" field.  However, if I select FREE or NA in the drop down in the PDF form, the amount does not change to $0.00, but stays as the amount / 11 as if there were GST on the amount.

I am not certain if the text is causing an issue or if it is the script.

I would be grateful if you could assist?

Thank you.

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

Use this:

var f = this.getField("Amount inc GST Row1");

var g = this.getField("GST CodeRow1").value;

if (g == "GST") event.value = f.value / 11;

else if (g == "FREE") event.value = 0;

else if (g == "NA") event.value = 0;

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

Thanks Bernd,

This worked!

Very helpful 🙂

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

You have several issues in your code, but Bernd's version of it should work fine.

It's important to understand the difference between the comparison operator ("==") and the value assignment operation ("=").

In some languages you can use the same operator for both, but not in JavaScript.

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