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.
1 Correct answer
Press Ctrl+J and check if there are any error messages there. My bet is you entered a wrong field name somewhere.
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;
}
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?
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.
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?
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.
Copy link to clipboard
Copied
Thanks for your help. It was a little glitch that slipped through the cracks.

