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.
The JavaScript itself is used to grab the data that has been entered into one form field, and when the checkbox is selected (checked), it copies that data to another field in the form. The form looks like this: Check this box if Billing Address and Mailing Address are the same. The JavaScript used to achieve the effect looks like this:
Acrobat JS Developer Guide Creating Acrobat DC form fields 65 You can use JavaScript to create a form field by invoking the addField method of the Doc object, which returns a Field object. This method permits you to specify the following information: The field name.
With it, for example, you can create a document that reports back a list of all form fields in the document, along with their types and values; another application is to summarize all comments in a document. The JavaScript for Acrobat API Reference has an example of the latter application in the Report object section.
Acrobat JS Developer Guide Digitally signing PDF documents 153 Secure forms You can lock form fields by creating a script containing a call to the Field object setLock method, and passing that script as the second parameter to the signature field setAction method.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With