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

I need a javascript formilar to compare two fields and return the higher one

Community Beginner ,
Aug 08, 2021 Aug 08, 2021

I need to compare the sum of fields 1,2,3 (sum#A) and compare it to field 4 (sum#B) and put the greater of sum A and B into field 5.  I am a newbie at this and need to know if there is a way to do that.  Thank you for all of your great support.

TOPICS
PDF forms
2.0K
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 ,
Aug 08, 2021 Aug 08, 2021

Place in calculation script of the field #5:

event.value=this.getField("sum#A").value>=this.getField("sum#B").value ? this.getField("sum#A").value : this.getField("sum#B").value;

@+

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 Beginner ,
Aug 08, 2021 Aug 08, 2021

I think I asked the wrong question.  After some thought I really need this:  I need to compare the values of two sets of 3 fields: the sum of 3 "priority" (P-1, P-2, P-3) fields and the sum of the 3 "non-priority" fields NP-1, NP-2, NP-3.  If sum of the priority fields (P-1+P-2+P-3)  are greater than the non-priority fields, then I need to set the field "NP-total" to 0 . Sorry for misstating the problem.

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 Beginner ,
Aug 08, 2021 Aug 08, 2021

I tried this but it does not work

{if (this.getField("2ea3").value>=this.getField("total_NP_uns").value) {
event.value = 0}}

where the 2ea3 field is the total priority (P-1, P-2 P-3) and the total_NP_uns) is the NP fields. The trigger to 0 does not work.

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 ,
Aug 09, 2021 Aug 09, 2021

Where does you use the script?

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 ,
Aug 09, 2021 Aug 09, 2021

In calculation script of the "total_NP_uns" field:

event.value=this.getField("NP-1").value+this.getField("NP-2").value+this.getField("NP-3").value;

and in validation script of this same field:

event.value=this.getField("2ea3").value>=event.value ? this.getField("2ea3").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 ,
Aug 09, 2021 Aug 09, 2021
LATEST

You don't need any JavaScript for doing this, just use the "Maximum" Acrobat's calculation:

 

Capture_30.png


Acrobate du PDF, InDesigner et Photoshopographe
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