Highlighted

## How do I make a simple calculation with only one of two different fields

Community Beginner ,
Sep 15, 2020

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?

You can use this code:

var fld1 = this.getField("Field1").value;
var fld2 = this.getField("Field2").value;
if(fld2 != ""){
event.value = fld2*1.25;}
else event.value = fld1*1.25;

TOPICS
Edit and convert PDFs, PDF forms

Views

54

Likes

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 do I make a simple calculation with only one of two different fields

Community Beginner ,
Sep 15, 2020

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?

You can use this code:

var fld1 = this.getField("Field1").value;
var fld2 = this.getField("Field2").value;
if(fld2 != ""){
event.value = fld2*1.25;}
else event.value = fld1*1.25;

TOPICS
Edit and convert PDFs, PDF forms

Views

55

Likes

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
2 Replies 2
Engaged ,
Sep 15, 2020

Copied

You can use this code:

var fld1 = this.getField("Field1").value;
var fld2 = this.getField("Field2").value;
if(fld2 != ""){
event.value = fld2*1.25;}
else event.value = fld1*1.25;

Likes

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
LATEST
Community Beginner ,
Sep 15, 2020

Copied

Perfecto! Thank you so much NesaNurani. ❤️

Likes

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
Resources