Highlighted

If or else if to choose from two textfield value

Explorer ,
Oct 28, 2020

Copy link to clipboard

Copied

Hello Adobe communty;

I need your help please. I have two text fields that a customer may enter value accoding to job requirement.

a. Total_EX_CFM    b. TOTAL_EXHAUST

What my calcuation should do is if TOTAL_EXHAUST = 0 then value of Total_EX_CFM selected in the calculation. Here is my code:

// TOTAL Exhaust calculation script
// field name for dividend and divisor
var Total_EX_CFM = "Total_EX_CFM";
var TOTAL_EXHAUST = "TOTAL_EXHAUST"; // name for the total for row or column field - the dividend
var RM_VOLUME = "RM_VOLUME"; // name for the grand total for rows and columns - the divisor

// Get field values as numbers
var Total_EX_CFM = Number(this.getField(Total_EX_CFM).value);
var TOTAL_EXHAUST = Number(this.getField(TOTAL_EXHAUST).value);
var RM_VOLUME = Number(this.getField(RM_VOLUME).value);
(function () {
// Perform calculation if denominator is not zero (or blank)
if (RM_VOLUME!== 0) {event.value = TOTAL_EXHAUST*60/ RM_VOLUME;}
else if (TOTAL_EXHAUST == 0) {event.value = Total_EX_CFM*60/ RM_VOLUME;}
else {event.value = "";} })();

 

Note: the if function works fine. The else if fuction isnot working. No error is diplaying in the console.

the code is under calculation --> custom calculation script:

 

Thank you.

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

> You were missing "" in field names

No, that's not the issue. The field names were defined earlier in the code.

That would have caused a different kind of error message to appear, too.

TOPICS
PDF forms

Views

60

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

If or else if to choose from two textfield value

Explorer ,
Oct 28, 2020

Copy link to clipboard

Copied

Hello Adobe communty;

I need your help please. I have two text fields that a customer may enter value accoding to job requirement.

a. Total_EX_CFM    b. TOTAL_EXHAUST

What my calcuation should do is if TOTAL_EXHAUST = 0 then value of Total_EX_CFM selected in the calculation. Here is my code:

// TOTAL Exhaust calculation script
// field name for dividend and divisor
var Total_EX_CFM = "Total_EX_CFM";
var TOTAL_EXHAUST = "TOTAL_EXHAUST"; // name for the total for row or column field - the dividend
var RM_VOLUME = "RM_VOLUME"; // name for the grand total for rows and columns - the divisor

// Get field values as numbers
var Total_EX_CFM = Number(this.getField(Total_EX_CFM).value);
var TOTAL_EXHAUST = Number(this.getField(TOTAL_EXHAUST).value);
var RM_VOLUME = Number(this.getField(RM_VOLUME).value);
(function () {
// Perform calculation if denominator is not zero (or blank)
if (RM_VOLUME!== 0) {event.value = TOTAL_EXHAUST*60/ RM_VOLUME;}
else if (TOTAL_EXHAUST == 0) {event.value = Total_EX_CFM*60/ RM_VOLUME;}
else {event.value = "";} })();

 

Note: the if function works fine. The else if fuction isnot working. No error is diplaying in the console.

the code is under calculation --> custom calculation script:

 

Thank you.

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

> You were missing "" in field names

No, that's not the issue. The field names were defined earlier in the code.

That would have caused a different kind of error message to appear, too.

TOPICS
PDF forms

Views

61

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
Oct 28, 2020 0
Adobe Community Professional ,
Oct 28, 2020

Copy link to clipboard

Copied

Try this:

if (RM_VOLUME!== 0) {
  if (TOTAL_EXHAUST == 0) event.value = Total_EX_CFM*60/ RM_VOLUME;
  else event.value = TOTAL_EXHAUST*60/ RM_VOLUME;
}
else event.value = "";

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...
Oct 28, 2020 0
Explorer ,
Oct 28, 2020

Copy link to clipboard

Copied

Bernd;

Thank you for quick reply. I replaced your code after the if function. However, it is not working at all.

It displays "SyntaxError: missing } after function body
17:"

Thank you

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...
Oct 28, 2020 0
Most Valuable Participant ,
Oct 28, 2020

Copy link to clipboard

Copied

Post your full code.

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...
Oct 28, 2020 0
Explorer ,
Oct 28, 2020

Copy link to clipboard

Copied

This is the current one:

// TOTAL Exhaust calculation script
// field name for dividend and divisor
var Total_EX_CFM = "Total_EX_CFM";
var TOTAL_EXHAUST = "TOTAL_EXHAUST"; // name for the total for row or column field - the dividend
var RM_VOLUME = "RM_VOLUME"; // name for the grand total for rows and columns - the divisor

// Get field values as numbers
var Total_EX_CFM = Number(this.getField(Total_EX_CFM).value);
var TOTAL_EXHAUST = Number(this.getField(TOTAL_EXHAUST).value);
var RM_VOLUME = Number(this.getField(RM_VOLUME).value);
(function () {
// Perform calculation if denominator is not zero (or blank)
if (RM_VOLUME!== 0) {
if (TOTAL_EXHAUST == 0) event.value = Total_EX_CFM*60/ RM_VOLUME;
else event.value = TOTAL_EXHAUST*60/ RM_VOLUME;
}
else event.value = "";}
);

 

my orginal is;

// Get field values as numbers

var Total_EX_CFM =  Number(this.getField(Total_EX_CFM).value);

var TOTAL_EXHAUST = Number(this.getField(TOTAL_EXHAUST).value);

var RM_VOLUME = Number(this.getField(RM_VOLUME).value);

(function () {

// Perform calculation if denominator is not zero (or blank)

if (RM_VOLUME!== 0) {event.value = TOTAL_EXHAUST*60/ RM_VOLUME;}

else if (TOTAL_EXHAUST == 0) {event.value = Total_EX_CFM*60/ RM_VOLUME;}

else {event.value = "";} })();

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...
Oct 28, 2020 0
Most Valuable Participant ,
Oct 28, 2020

Copy link to clipboard

Copied

You don't need this function stuff in the middle. Got rid of that line and the last one (in your first code) and it should work.

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...
Oct 28, 2020 0
Explorer ,
Oct 28, 2020

Copy link to clipboard

Copied

Do you mean like this? if so it is not working. Am I missing something?

// Get field values as numbers
var Total_EX_CFM = Number(this.getField(Total_EX_CFM).value);
var TOTAL_EXHAUST = Number(this.getField(TOTAL_EXHAUST).value);
var RM_VOLUME = Number(this.getField(RM_VOLUME).value);

 

// Perform calculation if denominator is not zero (or blank)
if (RM_VOLUME!== 0) {event.value = TOTAL_EXHAUST*60/ RM_VOLUME;}
else if (TOTAL_EXHAUST == 0) {event.value = Total_EX_CFM*60/ RM_VOLUME;}

 

Thank you

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...
Oct 28, 2020 0
Adobe Community Professional ,
Oct 28, 2020

Copy link to clipboard

Copied

Why doesn't you use my script?

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...
Oct 28, 2020 0
Engaged ,
Oct 28, 2020

Copy link to clipboard

Copied

You were missing "" in field names:

var Total_EX_CFM = Number(this.getField("Total_EX_CFM").value);
var TOTAL_EXHAUST = Number(this.getField("TOTAL_EXHAUST").value);
var RM_VOLUME = Number(this.getField("RM_VOLUME").value);

 

// Perform calculation if denominator is not zero (or blank)
if (RM_VOLUME!== 0) {event.value = TOTAL_EXHAUST*60/ RM_VOLUME;}
else if (TOTAL_EXHAUST == 0) {event.value = Total_EX_CFM*60/ RM_VOLUME;}

 

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...
Oct 28, 2020 0
Explorer ,
Oct 28, 2020

Copy link to clipboard

Copied

I did. I replaced my if statement with yours as you see on my reply the code is displaying an error.

 

// Perform calculation if denominator is not zero (or blank)

if (RM_VOLUME!== 0) {

  if (TOTAL_EXHAUST == 0) event.value = Total_EX_CFM*60/ RM_VOLUME;

  else event.value = TOTAL_EXHAUST*60/ RM_VOLUME;

}

else event.value = "";

 

Thank you.

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...
Oct 28, 2020 0
Adobe Community Professional ,
Oct 28, 2020

Copy link to clipboard

Copied

This script doesn't gives a error message.

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...
Oct 28, 2020 0
Explorer ,
Oct 28, 2020

Copy link to clipboard

Copied

After debugging line by line. I finally found the issue now it work perfect. Thank you to you all.

 

 

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...
Oct 28, 2020 0
Most Valuable Participant ,
Oct 28, 2020

Copy link to clipboard

Copied

> You were missing "" in field names

No, that's not the issue. The field names were defined earlier in the code.

That would have caused a different kind of error message to appear, too.

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...
Oct 28, 2020 1
Asim123 LATEST
Contributor ,
Oct 28, 2020

Copy link to clipboard

Copied

In his second post he only declared field names in his current code and not in his original code and in his 3rd post is his original code without "function" part and he is missing "" in that code so yes it is issue with that code.

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...
Oct 28, 2020 0