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

How can I copy text from one field to another using Javascript?

New Here ,
Feb 27, 2019 Feb 27, 2019

Copy link to clipboard

Copied

I am not very familiar with javascript.  I would like to copy text from one set of fields to another in a pdf (using Acrobat DC) based on the whether a checkbox has been checked or not (i.e., if checked box value = true, etc.).  How can I do this using javascript as an action for the checkbox field?  Assume the checkbox field name is check_yesno.  If it is checked (value is true) then I want to copy an address from one field on the form to another.   As an example, one of the fields I want to copy is address_main to be copied to address_secondary if the checkbox has been checked.  Any help with this would be appreciated.

TOPICS
Acrobat SDK and JavaScript , Windows

Views

1.4K

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Feb 27, 2019 Feb 27, 2019

Press Ctrl+J and check if there are any error messages there. My bet is you entered a wrong field name somewhere.

Votes

Translate

Translate
Community Expert ,
Feb 27, 2019 Feb 27, 2019

Copy link to clipboard

Copied

Should the "address_secondary" field be editable? If not then you can use its calculation script to do it.

If so, then you can use something like this as the custom Mouse Up script of the check-box:

if (event.target.value!="Off") {

     this.getField("address_secondary").value = this.getField("address_main").valueAsString;

}

Votes

Translate

Translate

Report

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 ,
Feb 27, 2019 Feb 27, 2019

Copy link to clipboard

Copied

Thanks for the suggestion.  The example works for one field.  How would I extend this code to be used for multiple fields of text to be moved based upon the checkbox being checked?

Votes

Translate

Translate

Report

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 ,
Feb 27, 2019 Feb 27, 2019

Copy link to clipboard

Copied

Simply add more lines of code like the one between the curly brackets, adjusting the field names in each one.

Make sure those lines are also inside those brackets, though.

Votes

Translate

Translate

Report

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 ,
Feb 27, 2019 Feb 27, 2019

Copy link to clipboard

Copied

Yes.  I assumed that and had already tried it.  When selecting the checkbox only the first of the fields gets copied - not the others.  Here is the actual code I used: 

if (event.target.value!="Off") {

     this.getField("father_address").value = this.getField("address").valueAsString;

     this.getField("father_apartment").value = this.getField("apartment").valueAsString;

     this.getField("father_city").value = this.getField("city").valueAsString;

     this.getField("father_state").value = this.getField("state").valueAsString;

     this.getField("father_zip_Code").value = this.getField("zip_code").valueAsString;

     this.getField("father_home_phone").value = this.getField("home_phone").valueAsString;

}

As I mentioned, this only copied the first field.  The target fields were empty, as they were supposed to be, but the text strings from the fields that were completed did not copy.  Is there something I'm missing in the code?

Votes

Translate

Translate

Report

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 ,
Feb 27, 2019 Feb 27, 2019

Copy link to clipboard

Copied

Press Ctrl+J and check if there are any error messages there. My bet is you entered a wrong field name somewhere.

Votes

Translate

Translate

Report

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 ,
Feb 28, 2019 Feb 28, 2019

Copy link to clipboard

Copied

LATEST

Thanks for your help.  It was a little glitch that slipped through the cracks. 

Votes

Translate

Translate

Report

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