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

Making a field only calculate if current field not blank and if current field plank the total field

New Here ,
Sep 29, 2021 Sep 29, 2021

New Issue

I have 3 fields   SG1  NG1  EG1    The simple calculation is EG1=NG1+SG1

I am trying to accomplish two objectives

If NG1 is blank  EG1 should be blank
If NG1 not blank  EG1=NG1+SG1

I have tried several things and the closest I can get is to place the math formula in the NG1 validate field, but the closest I can get always adds the Starting Value of NG1 +SG1 even when I update NG1.  It never adds the update value,
Also any one recommend any videos that explain java script for adobe pasr this, which is the most complicated script I have accomplishe with out help?

var level=this.getField("SL1").value;
if(event.target.value!="Off")this.getField("EL1").value=level+1;
if(event.target.value=="Off")
this.getField("EL1").value=level;

 

TOPICS
PDF forms
1.6K
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 ,
Sep 29, 2021 Sep 29, 2021

Don't use calculations in validations.

Use this as 'custom calculation script' of "EG1" field:

var a = Number(this.getField("NG1").value);
var b = Number(this.getField("SG1").value);
if(this.getField("NG1").valueAsString == "")
event.value = "";
else
event.value = a+b;

 

You writed if "NG1" is not blank EG1=NG1+SG1, so why you used 'level+1' in your script?

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 ,
Sep 29, 2021 Sep 29, 2021

Are you using checkboxes?

 

If not, why are you using "if (event.target.value !="Off")"?  The ON or OFF state corresponds to widgets, such as radio buttons or checkboxes.

 

Text field objects don't use this property, instead it should read 'if (event.target.value !="")' . Using the double quotes("") to declare a blanl value.

 

Also, please clarify exactly the name of all the calculated field objects in your form. In your inquiry yuo mentioned that you have 3 fields SG1 NG1 EG1. But then in your script you have different field names.

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 ,
Sep 30, 2021 Sep 30, 2021

It was a two part question, the first dealing with those three fields.

The second showing my level oof incompitence and wanting to learn more and asking if anyone had advice on where I could learn more,  I am use to c# and visual basic, so this is all new to me.

 

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 ,
Sep 29, 2021 Sep 29, 2021

Don't use calculations in validations.

Use this as 'custom calculation script' of "EG1" field:

var a = Number(this.getField("NG1").value);
var b = Number(this.getField("SG1").value);
if(this.getField("NG1").valueAsString == "")
event.value = "";
else
event.value = a+b;

 

You writed if "NG1" is not blank EG1=NG1+SG1, so why you used 'level+1' in your script?

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 ,
Sep 30, 2021 Sep 30, 2021
LATEST

Different Script, Just demonstrating my limits so far.    

 

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