• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Set default value of PDF form field as the value of another field in the same PDF form

New Here ,
Aug 03, 2020 Aug 03, 2020

Copy link to clipboard

Copied

Does anyone know how to make the default value in a field be equal to another field.

For example if I had a field called "Name" and I wanted that field contents to be the Default value in a field called "Name2".  The idea is not having to input the value twice but leaving the possibility to change the value in field "Name2" "the default value" to another value if desired.

TOPICS
Acrobat SDK and JavaScript

Views

8.7K

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
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 03, 2020 Aug 03, 2020

Custom calculation script.

 

Right-click on that field and select Properties from the context menu. Then go to the calculate tab.

 

See slide:

 

custom calc.png

Votes

Translate

Translate
Community Expert ,
Aug 03, 2020 Aug 03, 2020

Copy link to clipboard

Copied

There's always many ways to achieve this with javascripting.

 

In  my case, this simple line of code worked for me:

 

 

event.target.value = this.getField("Name").value;

 

 

Use the script as custom calculation script in field "Name".

Votes

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
community guidelines
Community Expert ,
Aug 03, 2020 Aug 03, 2020

Copy link to clipboard

Copied

You should use event.value here, not event.target.value .

Votes

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
community guidelines
New Here ,
Aug 03, 2020 Aug 03, 2020

Copy link to clipboard

Copied

Where do I put that?  I was thinking in the Default Value under options but that doesn't seem to work

Votes

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
community guidelines
Community Expert ,
Aug 03, 2020 Aug 03, 2020

Copy link to clipboard

Copied

If I use event.value instead of event.target.value the Name2 field is not editable.

 

Using event.value =  this.getField("Name").value;  just grabs the value from the other field and doesn't allow the user to type in something different in Name2 field.

Votes

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
community guidelines
Community Expert ,
Aug 04, 2020 Aug 04, 2020

Copy link to clipboard

Copied

I don't see why that should be the case. And at any rate event.value is how you assign a new value in a Calculation script. If you want the user to be able to manually overwrite the value that's possible, but will require adjusting the script to check the source of the event, or moving the code (and adjusting it, of course) to the Validation event of the Name field, for example.

Votes

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
community guidelines
Community Expert ,
Aug 04, 2020 Aug 04, 2020

Copy link to clipboard

Copied

Is that what you showed me one time with  "if (event.source && event.source.name =="FieldName") ??

Votes

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
community guidelines
Community Expert ,
Aug 04, 2020 Aug 04, 2020

Copy link to clipboard

Copied

Exactly, yes.

Votes

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
community guidelines
New Here ,
Aug 03, 2020 Aug 03, 2020

Copy link to clipboard

Copied

Where do I put that?  I was thinking in the Default Value under options but that doesn't seem to work

Votes

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
community guidelines
Community Expert ,
Aug 03, 2020 Aug 03, 2020

Copy link to clipboard

Copied

Custom calculation script.

 

Right-click on that field and select Properties from the context menu. Then go to the calculate tab.

 

See slide:

 

custom calc.png

Votes

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
community guidelines
New Here ,
Aug 03, 2020 Aug 03, 2020

Copy link to clipboard

Copied

Thanks!!

Votes

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
community guidelines
New Here ,
Aug 03, 2020 Aug 03, 2020

Copy link to clipboard

Copied

It works!!!  You the MAN!!

Votes

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
community guidelines
Community Expert ,
Aug 03, 2020 Aug 03, 2020

Copy link to clipboard

Copied

Great! happy to help and kudos to my mentor Try67 who consistently helps me to become better at this.

Votes

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
community guidelines
Community Beginner ,
Aug 02, 2022 Aug 02, 2022

Copy link to clipboard

Copied

I can't seem to get this to work in Acrobat Pro DC Continuous Release version 2022.001.20169 on Windows 11 version 21H2 OS Build 22000.795.  

 

event.target.value = this.getField("Name").value;

When I use the above JavaScript, the destination field updates correctly, and allows my users to manually edit the copied value, but the value itself reverts again as soon as any other field is updated.  

If I use event.value instead, I cannot edit the destination field at all.  

Votes

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
community guidelines
Community Expert ,
Aug 03, 2022 Aug 03, 2022

Copy link to clipboard

Copied

You need a different approach to do that. What's the name of the field you want to copy the value to?

Votes

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
community guidelines
Community Beginner ,
Aug 03, 2022 Aug 03, 2022

Copy link to clipboard

Copied

We have a pre- and post-travel report with two sections for expenses.  I would like a field called "Lodging.0" to copy its data into "Lodging travel report.0", but I want my users to be able to edit "Lodging travel report.0" in case there are changes to expenses during their trip.  As a workaround, we used a button that applies this formula when clicked: 

 

getField("Lodging travel report.0").value = getField("Lodging.0").valueAsString;

 

Which works, but I was hoping I could make it a bit more automatic.  I greatly appreciate your time and assistance.  

Votes

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
community guidelines
Community Expert ,
Aug 03, 2022 Aug 03, 2022

Copy link to clipboard

Copied

As the custom Validation script of "Lodging.0" enter the following:

 

this.getField("Lodging travel report.0").value = event.value;

 

Note this will also clear the second field if you clear the first. If you want to avoid that change the code to:

 

if (event.value) this.getField("Lodging travel report.0").value = event.value;

Votes

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
community guidelines
Community Expert ,
Aug 03, 2022 Aug 03, 2022

Copy link to clipboard

Copied

PS. And remove the calculation script from "Lodging travel report.0", of course, if it's still there.

Votes

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
community guidelines
Community Beginner ,
Aug 03, 2022 Aug 03, 2022

Copy link to clipboard

Copied

This seems to work exactly as I desired it to, thank you very much! 

Votes

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
community guidelines
New Here ,
Dec 22, 2022 Dec 22, 2022

Copy link to clipboard

Copied

LATEST

Can I add two/ multiple fields?

Votes

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
community guidelines