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

If then Statements for a Javascript in PDF form

New Here ,
Mar 10, 2017 Mar 10, 2017

Hellos,

I have created a form that I need to implement an If Then statement. Basically if the answer to one field is a "Product" then I need a particular field to return a Value  as 10.

Basically If Field A is ProductA  Field B=10
If Field A is ProductB then Field B =15
If Field A is ProductC then Field B = 20
Is there a way that this can be incorporated as a formula?

Thank you

Varghese J

TOPICS
PDF forms
30.3K
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
Community Expert ,
Mar 10, 2017 Mar 10, 2017

Sure. You can use this code as the custom calculation script for "Field B":

var fieldA = this.getField("Field A").valueAsString;

if (fieldA=="ProductA") event.value = 10;

else if (fieldA=="ProductB") event.value = 15;

else if (fieldA=="ProductC") event.value = 20;

else event.value = "";

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 ,
Mar 10, 2017 Mar 10, 2017

Sure. You can use this code as the custom calculation script for "Field B":

var fieldA = this.getField("Field A").valueAsString;

if (fieldA=="ProductA") event.value = 10;

else if (fieldA=="ProductB") event.value = 15;

else if (fieldA=="ProductC") event.value = 20;

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
New Here ,
Feb 07, 2020 Feb 07, 2020

So I have this custom calc to auto populate phone numbers if a certain insurance is selected... but my insurance field is set to allow custom text for third party insurances. How do I add a code to allow for custom text if a custom text is put in the insurance section? 

 

var fieldA = this.getField("Insurance").valueAsString;
if (fieldA=="BCBS Federal") event.value = ("1(800)442-4607");
else if (fieldA=="BCBS TX") event.value = ("1(800)451-0287");
else if (fieldA=="BCBS") event.value = ("1(800)676-2583");
else if (fieldA=="UHC") event.value = ("1(877)842-3210");
else if (fieldA=="Cigna") event.value = ("1(800)244-6224");
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
Community Expert ,
Feb 07, 2020 Feb 07, 2020

The problem with making this field available for manual entry as it is now, is that it's fighting the calculation. Since the value of this field is set from a single source, it is a simple matter to move the script to that source, which means there is no conflict for manual entry. This is your best solution. 

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

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 24, 2020 Mar 24, 2020

Would you by chance know of a tutorial for this?   I know pretty much nothing about any of this, but i'm trying.   I did get my document to work using the script above, but i would also like my people to be able to enter custom text.  However I have no clue now to do it.

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 ,
Mar 24, 2020 Mar 24, 2020

Here:

https://acrobatusers.com/tutorials/change_another_field/

 

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

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

Hi! I hope someone might help me.

I have this script but it doesn't seem to run. I have no errors popping up.

The Units field is a drop-down menu.

Script is set up under "Rate" field:

var Units = this.getField("Units").value;
if (Units=="50") event.value = 75;
else if (Units=="100") event.value = 119;
else if (Units=="150") event.value = 125;
else event.value = "False"

I'd like to have $ signs also, but when it didn't work I took them out.

I set the "Units" field to "Commit selected value immediately" under the options.

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

Hi! I hope someone might help me.

I have this script but it doesn't seem to run. I have no errors popping up.

The Units field is a drop-down menu.

Script is set up under "Rate" field:

var Units = this.getField("Units").value;
if (Units=="50") event.value = 75;
else if (Units=="100") event.value = 119;
else if (Units=="150") event.value = 125;
else event.value = "False"

I'd like to have $ signs also, but when it didn't work I took them out.

I set the "Units" field to "Commit selected value immediately" under the options.

I appreciate any advice!

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, 2020 Apr 22, 2020
LATEST

Please post this to a new thread and provide more info, such as the exact location of the script. Is it a calcualtion? a format? etc. 

 

 

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

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