Highlighted

How to create a simple calculation with a variable

Community Beginner ,
Sep 15, 2020

Copy link to clipboard

Copied

Hi! I have a simple calculation that pulls from two different fields. The first field is ALWAYS filled out, and the second field is only filled out once in a while. But if the second field IS filled out, then the info in the first field isn't the correct variable for the calculation, and I need the number from the second field.

For example:

 

Field 1 = 3

Field 2 = "blank"

Calculation Field is:

Field 1 * 1.25 (or 3 * 1.25 = 3.75)

 

But if the user does this:

Field 1 = 3

Field 2 = 4

Then the calculation field is:

Field 2 * 1.25 (or 4 * 1.25 = 5)

 

However, I can't keep one visible and hide the other (I think) because I still need the data in Field 1 to still be seen. Is there a code I can add to the "Custom Calculation Script" section of the "Text Field Properties" box?

TOPICS
General troubleshooting, How to, PDF forms

Views

56

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

How to create a simple calculation with a variable

Community Beginner ,
Sep 15, 2020

Copy link to clipboard

Copied

Hi! I have a simple calculation that pulls from two different fields. The first field is ALWAYS filled out, and the second field is only filled out once in a while. But if the second field IS filled out, then the info in the first field isn't the correct variable for the calculation, and I need the number from the second field.

For example:

 

Field 1 = 3

Field 2 = "blank"

Calculation Field is:

Field 1 * 1.25 (or 3 * 1.25 = 3.75)

 

But if the user does this:

Field 1 = 3

Field 2 = 4

Then the calculation field is:

Field 2 * 1.25 (or 4 * 1.25 = 5)

 

However, I can't keep one visible and hide the other (I think) because I still need the data in Field 1 to still be seen. Is there a code I can add to the "Custom Calculation Script" section of the "Text Field Properties" box?

TOPICS
General troubleshooting, How to, PDF forms

Views

57

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
Sep 15, 2020 0
Most Valuable Participant ,
Sep 27, 2020

Copy link to clipboard

Copied

You can use something like this:

 

var v1 = this.getField("Field 1").valueAsString;

var v2 = this.getField("Field 2").valueAsString;

if (v2=="") event.value = Number(v1) * 1.25;

else event.value = Number(v2) * 1.25;

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
Reply
Loading...
Sep 27, 2020 0
Asim123 LATEST
Contributor ,
Sep 27, 2020

Copy link to clipboard

Copied

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
Reply
Loading...
Sep 27, 2020 0