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

New Here ,
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.

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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

TOPICS
Acrobat SDK and JavaScript, Windows

Views

175

Likes

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

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

New Here ,
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.

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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

TOPICS
Acrobat SDK and JavaScript, Windows

Views

176

Likes

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
Feb 27, 2019 0
Most Valuable Participant ,
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;

}

Likes

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
Reply
Loading...
Feb 27, 2019 0
New Here ,
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?

Likes

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
Reply
Loading...
Feb 27, 2019 0
Most Valuable Participant ,
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.

Likes

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
Reply
Loading...
Feb 27, 2019 0
New Here ,
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?

Likes

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
Reply
Loading...
Feb 27, 2019 0
Most Valuable Participant ,
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.

Likes

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
Reply
Loading...
Feb 27, 2019 1
New Here ,
Feb 28, 2019

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Feb 28, 2019 0