Skip to main content
cmvarga5
Known Participant
May 29, 2025
Answered

Auto-populate text from one form field to another depending on which checkbox is ticked

  • May 29, 2025
  • 2 replies
  • 1958 views

I know that we can auto-populate information from one text field to another by keeping the same form name. However, I require a text field to populate in another text field if a checkbox is selected.

 

For example, I have two checkboxes:
__ CURRENT and __ NEW

Amount $________________.

Current Amount $ _____________ (auto-populate from amount field if current is checked)

New Amount $ _______________ (auto-populate from amount field if new is checked)

 

If current is selected, there is an amount field that is to be populated in another text field. If new is selected, that same amount field will be populated in another text field.

 

Is this possible?

 

Correct answer Thom Parker

Hi @Thom Parker ,

Now that I have these fields working, if let's say the person checked off the New checkbox and the amount populates in the field I want it to, how can they enter another amount in the Current form field? I also put that same script for that field if the Current checkbox is clicked. It is not allowing them to type anything in there now.


The calculation script is overwritting anything that the user entered.  There are a few different ways to allow the user to enter a value into the field that is not selected.  Probably the easiest is to simple not overwrite the value in the non-selected field. This presents another problem though.  If the user selectes New, then the new feild is populated with the entered value. If they then select Current, then that field is populated with the entered value, but because the non-selected value is not overwritten the New value remains, so both fields now have the same value. 

 

Here are the modified scripts. If this does not work for you then you will need to outline the exact behavior you want. And I mean exact, down to the tiny details. 

 

 

// Script for Current Amount field
if(this.getField("Check").value == "CURRENT")
    event.value = this.getField("Amount").value;

 

// Script for New Amount field
if(this.getField("Check").value == "NEW")
    event.value = this.getField("Amount").value;

 

 

2 replies

PDF Automation Station
Community Expert
Community Expert
May 29, 2025

Give the check boxes the same name, but different export values ("CURRENT" and "NEW").  Enter the following Mouse Up script in both check boxes:

if(event.target.value=="CURRENT")
{
this.getField("Current Amount").value = this.getField("Amount").value;
this.getField("New Amount").value = "";
}
else if (event.target.value=="NEW")
{
this.getField("Current Amount").value = "";
this.getField("New Amount").value = this.getField("Amount").value;
}
else
{
this.getField("Current Amount").value = "";
this.getField("New Amount").value = "";
}

Name the text fields as I have or change the names in the script to match the names of your text fields.

cmvarga5
cmvarga5Author
Known Participant
May 29, 2025

Thank you so much!!!

PDF Automation Station
Community Expert
Community Expert
May 29, 2025

You're welcome.  The difference between the script I provided and the one @Thom Parker provided is that mine is triggered by the checkbox selection (or deselection).  That means the values in the other fields will only change when the check boxes are clicked.  If you change Amount after the fact it won't change the other field values.  Thom's are triggered any time any field value changes so they will always take into account the checkbox selection and the Amount value.  However, since they are 2 separate check boxes, the user could check both.

Thom Parker
Community Expert
Community Expert
May 29, 2025

You'll need to place a custom calculation script on each of the "Current" and  "New Fields".

 

To do this correctly you'll need to know the exact names of the form fields. The script below uses names I made up. These have to be changed to the names in the real form for the script to work. 

 

// Script for Current Amount field
event.value = (this.getField("CurrentCheck").value != "Off")?this.getField("Amount").value:"";

 

// Script for New Amount field
event.value = (this.getField("NewCheck").value != "Off")?this.getField("Amount").value:"";

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
cmvarga5
cmvarga5Author
Known Participant
May 29, 2025

Thank you so much!