Index matching with form  SOLVED

Forum for the PDF-XChange Editor - Free and Licensed Versions

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Ocasio
User
Posts: 10
Joined: Thu Oct 17, 2019 3:06 pm

Index matching with form

Post by Ocasio »

Hello, I am trying to make a field value change based on another field value

var PP = this.getField("Primary Person").value
if( PP = "Person 2" ) event.value = "010101";
else if( PP = "Person 5" ) event.value = "058916";

In this case, I want "010101" to be automatically fill in the field value if the field "Primary Person" is filled with "Person 2", which has a dropdown menu of 5 persons.
User avatar
TrackerSupp-Daniel
Site Admin
Posts: 8613
Joined: Wed Jan 03, 2018 6:52 pm

Re: Index matching with form

Post by TrackerSupp-Daniel »

Hi, Ocasio

Dropdown fields are a type of combobox, as such you will likely need to use the "getItemAt" method to identify which item is being selected and denote special handling for each item. Please find more details in the Adobe JS API reference, on page 456:
https://www.adobe.com/content/dam/acom/ ... f#page=456

Kind regards,
Dan McIntyre - Support Technician
Tracker Software Products (Canada) LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
Ocasio
User
Posts: 10
Joined: Thu Oct 17, 2019 3:06 pm

Re: Index matching with form

Post by Ocasio »

I did try the code on a text field rather than a dropdown box, still not getting the expected results. Could you tell me if the code is wrong?
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17948
Joined: Mon Jan 12, 2009 8:07 am
Location: London

Re: Index matching with form

Post by Tracker Supp-Stefan »

Hello Ocasio,

Please take a look at the attached sample on how you can make this work:
Drop_down_JS_test.pdf

Kind regards,
Stefan
You do not have the required permissions to view the files attached to this post.
Ocasio
User
Posts: 10
Joined: Thu Oct 17, 2019 3:06 pm

Re: Index matching with form

Post by Ocasio »

Thank you, is very close but not quite what i am looking for

For example, if Dropdown is "Option 1" then Text 2 is "00155"

Its a match table, none of the characters in one field are repeated in the other field

User name | User ID
Maria = 00155
Ralph = 87449
Etc...
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17948
Joined: Mon Jan 12, 2009 8:07 am
Location: London

Re: Index matching with form  SOLVED

Post by Tracker Supp-Stefan »

Hello Ocasio,

Certainly - here's the modified script showing you how you can push an arbitrary value for the text field (I've only covered the "first" option, and the others I left as they were - to keep my sample showing both options. You can obviously just make checks for each of the values in the drop down, and push the desired value in the text field from it:
Drop_down_JS_test_modified.pdf

Kind regards,
Stefan
You do not have the required permissions to view the files attached to this post.
Ocasio
User
Posts: 10
Joined: Thu Oct 17, 2019 3:06 pm

Re: Index matching with form

Post by Ocasio »

Thank you, I modified and it works fine like this.

Code: Select all

if (event.willCommit)
{
if (event.value == "Option 1"){
	this.getField("Text1").value = "01";
	}
	else if (event.value == "Option 2"){
    this.getField("Text1").value = "02";
    }
    else if (event.value == "Option 3"){
      this.getField("Text1").value = "03";
      }
      else if (event.value == "Option 4"){
        this.getField("Text1").value = "04";
        }
        else if (event.value == "Option 5"){
          this.getField("Text1").value = "05";
          }
          else if (event.value == "Option 6"){
            this.getField("Text1").value = "06";
            }
            else if (event.value == "Option 7"){
              this.getField("Text1").value = "07";
              }
              else if (event.value == "Option 8"){
                this.getField("Text1").value = "08";
                }
                else if (event.value == "Option 9"){
                  this.getField("Text1").value = "09";
                  }
                  else if (event.value == "Option 10"){
                    this.getField("Text1").value = "10";
                    }
}
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17948
Joined: Mon Jan 12, 2009 8:07 am
Location: London

Re: Index matching with form

Post by Tracker Supp-Stefan »

Hello Ocasio,

Glad I could help!

Kind regards,
Stefan