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

Acrobat Javascript assistance for comparing multiple fields and providing output

Explorer ,
Mar 15, 2023 Mar 15, 2023

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
3.3K
Translate
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
2 ACCEPTED SOLUTIONS
Community Expert ,
Mar 15, 2023 Mar 15, 2023

You must change the order of the comparisons.

View solution in original post

Translate
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

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;
}

View solution in original post

Translate
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

Replace

event.value = "TEM";

with

event.value = TEM;

Translate
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

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. 

Translate
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

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

Translate
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

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

Translate
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

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

Translate
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

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. 

Translate
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

Yes, I understood. See my previous advice.

Translate
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

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

Translate
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

That's absolutely NOT what I said.

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

Translate
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

You must change the order of the comparisons.

Translate
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

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;
}

Translate
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

I can't see any change.

Translate
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

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;
}

Translate
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

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;
}

Translate
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

That worked! Thank you!!!

Translate
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