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

Acrobat Javascript assistance for comparing multiple fields and providing output

Explorer ,
Mar 15, 2023 Mar 15, 2023

Copy link to clipboard

Copied

This one is a doozy for my non-programming head. I have tried to at least define the syntax for a javascript but I just can't wrap my head around the code for the following:

- I have 3 textboxes: "Total_Equipped_Move", "Total_Packed_Move" and "Total_Equipped_Packed".

- "Total_Equipped_Move" has a value calculated from other text boxes.
- "Total_Packed_Move" has a value calculated from other text boxes.

- "Total_Equipped_Packed" has a value calculated from other text boxes.


I would like the "MoveRate" textbox to display the lesser value between "Total_Equipped_Move" and "Total_Packed_Move" unless the sum of "Total_Equipped_Packed" is 16 or greater, then output "0".

I've taken a stab at it but my output is "TEM" instead of the value of "TEM", which also means that neither follow on statements are being calculated:

var TEM = Number(this.getField("Total_Equipped_Move").valueAsString);
var TPM = Number(this.getField("Total_Packed_Move").valueAsString);
var TEP = Number(this.getField("Total_Equipped_Packed").valueAsString);
if (TEM < TPM) {
event.value = "TEM";
}
else if (TEM > TPM) {
event.value = "TPM";
}
else if (TEP > 16) {
event.value = "0";
}

Assistance would be greatly appreciated. Thanks in advance!

TOPICS
How to , JavaScript

Views

2.4K

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 2 Correct answers

Community Expert , Mar 15, 2023 Mar 15, 2023

You must change the order of the comparisons.

Votes

Translate

Translate
Explorer , Mar 15, 2023 Mar 15, 2023

Good grief, one more try to get it right:

var TEM = Number(this.getField("Total_Equipped_Move").valueAsString);
var TPM = Number(this.getField("Total_Packed_Move").valueAsString);
var TEP = Number(this.getField("Total_Equipped_Packed").valueAsString);
if (TEP > 16) {
event.value = 0;
}
else if (TEM > TPM) {
event.value = TPM;
}
else if (TEM < TPM) {
event.value = TEM;
}

Votes

Translate

Translate
Community Expert ,
Mar 15, 2023 Mar 15, 2023

Copy link to clipboard

Copied

Replace

event.value = "TEM";

with

event.value = TEM;

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 ,
Mar 15, 2023 Mar 15, 2023

Copy link to clipboard

Copied

Awesome, thanks. I removed the "" from all 3 event.values. That was a goof on my part. 🙂 
However, it still does not appear to be calculating the last else/if statement. 

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 ,
Mar 15, 2023 Mar 15, 2023

Copy link to clipboard

Copied

The last clause can only happen if both values are equal, and larger than 16. Is that what you had in mind?

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 ,
Mar 15, 2023 Mar 15, 2023

Copy link to clipboard

Copied

No, it should supersede the output of the first two values.

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 ,
Mar 15, 2023 Mar 15, 2023

Copy link to clipboard

Copied

Then it should appear as the first condition, not the last one.

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 ,
Mar 15, 2023 Mar 15, 2023

Copy link to clipboard

Copied

Maybe that wasn't the best explanation. Let me try again:

If TEM is < TPM, then choose TEM. If TEM is > TPM then choose TPM. If TEP is  > 16, then ignore TEM and TPM and output 0. 

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 ,
Mar 15, 2023 Mar 15, 2023

Copy link to clipboard

Copied

Yes, I understood. See my previous advice.

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 ,
Mar 15, 2023 Mar 15, 2023

Copy link to clipboard

Copied

Ah, bummer. So there's no way then. Okay, thanks for your help.

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 ,
Mar 15, 2023 Mar 15, 2023

Copy link to clipboard

Copied

That's absolutely NOT what I said.

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 ,
Mar 15, 2023 Mar 15, 2023

Copy link to clipboard

Copied

LATEST

My apologies, I appear to have misunderstood you. I see, after re-reading, that you were saying that the order of the comparisons was the issue, which is what Bernd, below, said. Thanks again and my bad for misunderstanding.

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 ,
Mar 15, 2023 Mar 15, 2023

Copy link to clipboard

Copied

You must change the order of the comparisons.

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 ,
Mar 15, 2023 Mar 15, 2023

Copy link to clipboard

Copied

So, like this?

var TEM = Number(this.getField("Total_Equipped_Move").valueAsString);
var TPM = Number(this.getField("Total_Packed_Move").valueAsString);
var TEP = Number(this.getField("Total_Equipped_Packed").valueAsString);
if (TEM < TPM) {
event.value = TEM;
}
else if (TEM > TPM) {
event.value = TPM;
}
else if (TEP > 16) {
event.value = 0;
}

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 ,
Mar 15, 2023 Mar 15, 2023

Copy link to clipboard

Copied

I can't see any change.

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 ,
Mar 15, 2023 Mar 15, 2023

Copy link to clipboard

Copied

Ooof, my bad. Long day already!

var TEM = Number(this.getField("Total_Equipped_Move").valueAsString);
var TPM = Number(this.getField("Total_Packed_Move").valueAsString);
var TEP = Number(this.getField("Total_Equipped_Packed").valueAsString);
if (TEP > 16) {
event.value = "0";
}
else if (TEM > TPM) {
event.value = "TPM";
}
else if (TEM < TPM) {
event.value = TEM;
}

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 ,
Mar 15, 2023 Mar 15, 2023

Copy link to clipboard

Copied

Good grief, one more try to get it right:

var TEM = Number(this.getField("Total_Equipped_Move").valueAsString);
var TPM = Number(this.getField("Total_Packed_Move").valueAsString);
var TEP = Number(this.getField("Total_Equipped_Packed").valueAsString);
if (TEP > 16) {
event.value = 0;
}
else if (TEM > TPM) {
event.value = TPM;
}
else if (TEM < TPM) {
event.value = TEM;
}

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 ,
Mar 15, 2023 Mar 15, 2023

Copy link to clipboard

Copied

That worked! 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