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

If or else if to choose from two textfield value

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

TOPICS
PDF forms

Views

789

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
community guidelines

correct answers 3 Correct answers

Community Expert , Oct 28, 2020 Oct 28, 2020

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 = "";

Votes

Translate

Translate
Community Expert , Oct 28, 2020 Oct 28, 2020

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.

Votes

Translate

Translate
Community Expert , Oct 28, 2020 Oct 28, 2020

> 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.

Votes

Translate

Translate
Community Expert ,
Oct 28, 2020 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 = "";

Votes

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
community guidelines
Explorer ,
Oct 28, 2020 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

Votes

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
community guidelines
Community Expert ,
Oct 28, 2020 Oct 28, 2020

Copy link to clipboard

Copied

Post your full code.

Votes

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
community guidelines
Explorer ,
Oct 28, 2020 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 = "";} })();

Votes

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
community guidelines
Community Expert ,
Oct 28, 2020 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.

Votes

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
community guidelines
Explorer ,
Oct 28, 2020 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

Votes

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
community guidelines
Community Expert ,
Oct 28, 2020 Oct 28, 2020

Copy link to clipboard

Copied

Why doesn't you use my script?

Votes

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

Votes

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
community guidelines
Community Expert ,
Oct 28, 2020 Oct 28, 2020

Copy link to clipboard

Copied

This script doesn't gives a error message.

Votes

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

 

 

Votes

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
community guidelines
Community Expert ,
Oct 28, 2020 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;}

 

Votes

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
community guidelines
Community Expert ,
Oct 28, 2020 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.

Votes

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
community guidelines
Enthusiast ,
Oct 28, 2020 Oct 28, 2020

Copy link to clipboard

Copied

LATEST

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.

Votes

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
community guidelines