Copy field values โ€‹โ€‹in Acrobat using Javascript

How to copy form field values โ€‹โ€‹from one set of fields to another using javascript.

The idea here is to use the "Use Delivery / Billing Address" button, which copies user information from one block of fields to another identical set of fields.

I am now invoking an action on a button click to execute the following javascript:

this.field1.value = this.field2.value; 

However, this action results in an "undefined" error in the debugger.

+8
javascript pdf acrobat
source share
2 answers

For posterity, this is the solution to the problem:

 getField("field2").value = getField("field1").valueAsString; 

Also note that field2 set to field1 , so the order is reversed.

+15
source share

I used the following code to avoid overwriting the value in the second field if it already has something in it:

 //Set the source and destination vars: var source = this.getField("Box1"); var destination = this.getField("Box2"); //See if destination is empty and if so, insert source value if(destination.value==''||destination.value==null){destination.value=source.value} 

I used it on the "On Blur" of the source field, but you could use the button with "Mouse Up" as a trigger. (I found code on this website . It includes more sophisticated options for populating multiple fields or even combining values โ€‹โ€‹from two source fields into a single destination field.)

+4
source share

All Articles