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

script to use a portion of a form field to fill another form field

Community Beginner ,
Jan 10, 2020 Jan 10, 2020

Is there a way to have a form field consist of 17 characters (that I know how to do) and then elsewhere in the same PDF have a field that uses only a subset of that field... such as the last 8 characters or only the first character.

Example field name is : MiddleName and later on I want field MiddleInitial which would autofill just the first letter of the field MiddleName.

or

Example field name is Claim_Number, (a 17 character field) and later on I want field Last8_Claim which would autofill with the last 8 characters of the field Claim_Number.

 

I feel like I have seen the answer somewhere but just can't find the right query phrase to bring up the script or validation or calculation etc...

TOPICS
Create PDFs , Edit and convert PDFs , How to , PDF forms
4.6K
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 ,
Jan 10, 2020 Jan 10, 2020

Hi,

 

You can use the following as a reference.

 

First set the string length of the Claim_Number field using the following guidance :

https://answers.acrobatusers.com/set-field-based-string-length-field-q3335.aspx 

 

Then use these other threads to see how a script is phrased to extract the desired strings:
https://answers.acrobatusers.com/Extract-First-Letter-from-Text-field-q102091.aspx 


https://answers.acrobatusers.com/how-extract-characters-string-q41957.aspx 

 

More in-depth resource about using strings:
https://acrobatusers.com/tutorials/splitting-and-rebuilding-strings/ 

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 Beginner ,
Jan 14, 2020 Jan 14, 2020

Thanks everybody you got me to the right place .... and for other relative noobs like me here is the specifics.

First page of PDF has a field of 17 characters named Buy_VIN1

On several other pages I need just the last 8 characters of Buy_VIN1

On those other pages there is a text field named VIN1_R8 (doesn't really matter as that field name does not appear in the java script)

In the Form Editior mode I went to VIN1_R8 and in the CALCULATE box I entered the following:

 

var v1 = this.getField("Buy_VIN1").value;

var s1 = "";

if (v1.length > 0)
{
s1 = v1.substring(09,17);
}
event.value = String(s1);

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 ,
Jan 10, 2020 Jan 10, 2020

Yes, you just need to copy a portion of the string entered into the field to a different field. The best way to do this is with the validation script on the first field, say the MiddleName field.

 

Use something like this to copy the first letter

 

this.getField("MiddleInitial").value = (event.value.length > 0)?event.value[0]:"";

 

Or to get the last 8 letters 

 

this.getField("PartialName").value = (event.value.length > 8)?event.value.slice(event.value.length-8):event.value;

 

You just need to learn about the JavaScript string functions. 

Here's an article that covers some of what you can do

https://acrobatusers.com/tutorials/splitting-and-rebuilding-strings/

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Jan 10, 2020 Jan 10, 2020

Hi,

 

You can use the following as a reference.

 

First set the string length of the Claim_Number field using the following guidance :

https://answers.acrobatusers.com/set-field-based-string-length-field-q3335.aspx 

 

Then use these other threads to see how a script is phrased to extract the desired strings:
https://answers.acrobatusers.com/Extract-First-Letter-from-Text-field-q102091.aspx 


https://answers.acrobatusers.com/how-extract-characters-string-q41957.aspx 

 

More in-depth resource about using strings:
https://acrobatusers.com/tutorials/splitting-and-rebuilding-strings/ 

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 ,
Jan 14, 2020 Jan 14, 2020

Thanks everybody you got me to the right place .... and for other relative noobs like me here is the specifics.

First page of PDF has a field of 17 characters named Buy_VIN1

On several other pages I need just the last 8 characters of Buy_VIN1

On those other pages there is a text field named VIN1_R8 (doesn't really matter as that field name does not appear in the java script)

In the Form Editior mode I went to VIN1_R8 and in the CALCULATE box I entered the following:

 

var v1 = this.getField("Buy_VIN1").value;

var s1 = "";

if (v1.length > 0)
{
s1 = v1.substring(09,17);
}
event.value = String(s1);

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
New Here ,
May 13, 2020 May 13, 2020

I love you so much right now!  I was needing to grab the last 8 of VIN's also, and I couldn't get anything else to work.  Thank you, thank you, 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
Community Beginner ,
May 13, 2020 May 13, 2020
LATEST

you are very welcome.....

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