Copy field values in Acrobat using Javascript

37,384

Solution 1

For posterity, this is the solution to the problem:

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

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

Solution 2

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

//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 "On Blur" of the source Field, but you could use a button with "Mouse Up" as the trigger. (I found the code on this website. It includes more complicated options for populating multiple fields or even joining values from two source fields into one destination field.)

Share:
37,384
CaseyHunt
Author by

CaseyHunt

Updated on July 29, 2020

Comments

  • CaseyHunt
    CaseyHunt almost 4 years

    How can I copy the form field values from one set of fields to another using javascript.

    The idea here is to have a 'use shipping/billing address' type of button that copies the user information from one block of fields to another identical set of fields.

    Right now, I call an action upon click of a button to execute the following javascript:

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

    However that action yields an 'undefined' error in the debugger.