Auto-populate a field when it's empty
Copy link to clipboard
Copied
Hi!
I was trying to auto-populate a field with data of another one but only if the field is empty. I can populate the field, the problem is that the 2nd field doesn't update when I made a change in the 1st field.
What I have so far is this:
var a = this.getField("FieldName");
if (event.target.value=="")
{
event.target.value=a.value
}
Copy link to clipboard
Copied
Why should it? It already has a value... You need to better define how you want this to work.
Do you want the field to be editable by the user, but if the first field's value is changed that it should overwrite any user-entered value?
Copy link to clipboard
Copied
Yes! That's right. For example, I'm entering my Insurance beneficiary's information in field 1, but then I realized that I misspelled the word or I changed my mind and want to change my beneficiary. So, in the next page I have a funds form that also ask for my beneficiary information. It's not required to be the same as the insurance beneficiary but I realized that most people put the same information. So I want to populate those fields with the same insurance beneficiary information, but they'll have a chance to modified it if they want to put another person as beneficiary for their funds.
Does that make sense? Sorry, I've never studied how to use adobe javascript. This is just a one time work and I need help ><
Copy link to clipboard
Copied
You can use a button that will copy the value from the first field to the second when clicked.
The code for that button's MouseUp event will be something like this:
this.getField("Text2").value = this.getField("Text1").valueAsString;

