Skip to main content
Inspiring
March 15, 2023
Answered

Acrobat Javascript assistance for comparing multiple fields and providing output

  • March 15, 2023
  • 2 replies
  • 3763 views

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!

This topic has been closed for replies.
Correct answer charleyp1

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


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

2 replies

Bernd Alheit
Adobe Expert
March 15, 2023

You must change the order of the comparisons.

charleyp1Author
Inspiring
March 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;
}

Bernd Alheit
Adobe Expert
March 15, 2023

I can't see any change.

Bernd Alheit
Adobe Expert
March 15, 2023

Replace

event.value = "TEM";

with

event.value = TEM;

charleyp1Author
Inspiring
March 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. 

try67
Adobe Expert
March 15, 2023

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