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.
Custom calculation script.
Right-click on that field and select Properties from the context menu. Then go to the calculate tab.
See slide:
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".
Copy link to clipboard
Copied
You should use event.value here, not event.target.value .
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
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.
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.
Copy link to clipboard
Copied
Is that what you showed me one time with "if (event.source && event.source.name =="FieldName") ??
Copy link to clipboard
Copied
Exactly, yes.
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
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:
Copy link to clipboard
Copied
Thanks!!
Copy link to clipboard
Copied
It works!!! You the MAN!!
Copy link to clipboard
Copied
Great! happy to help and kudos to my mentor Try67 who consistently helps me to become better at this.
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.
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?
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.
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;
Copy link to clipboard
Copied
PS. And remove the calculation script from "Lodging travel report.0", of course, if it's still there.
Copy link to clipboard
Copied
This seems to work exactly as I desired it to, thank you very much!
Copy link to clipboard
Copied
Can I add two/ multiple fields?