Skip to main content
Participating Frequently
March 20, 2020
Answered

Auto populate text field based on input in other field

  • March 20, 2020
  • 2 replies
  • 2502 views

Hoping to be able to get a text box to populate automatically in an adobe form I created.  I would like when a customer puts their initials in box 1 for the text in box 2 to populate in box 3.  For example if a customer was to put their initials in box 1, the price listed in box 2 would then populate into box 3.  I have gotten close to the formula but have not found a sting that quite works.  Thank you!

This topic has been closed for replies.
Correct answer ls_rbls

Hi,

 

In  Box1 add the following line of code as Custom Calculation Script:

if (!event.willCommit)
console.println(!event.value);

{
this.getField("Box2").value;
}

 

And in Box3 add this line of code as Custom Calculation Script:

var s = this.getField("Box1").value;
var t = this.getField("Box2").value;

if (s=="") event.value = "";

else event.value = t

2 replies

ls_rbls
Community Expert
ls_rblsCommunity ExpertCorrect answer
Community Expert
March 24, 2020

Hi,

 

In  Box1 add the following line of code as Custom Calculation Script:

if (!event.willCommit)
console.println(!event.value);

{
this.getField("Box2").value;
}

 

And in Box3 add this line of code as Custom Calculation Script:

var s = this.getField("Box1").value;
var t = this.getField("Box2").value;

if (s=="") event.value = "";

else event.value = t
Linda5579Author
Participating Frequently
March 24, 2020

THANK YOU! I have been watching tutorials and working on this one for days. That worked perfectly!

ls_rbls
Community Expert
Community Expert
March 24, 2020

You're welcome, happy to help.

 

Would you mind marking my answer as correct?

 

It means a world to me .

Inspiring
March 20, 2020

Post your latest attempt and include where you placed the script, and we can provide some guidance. Will there always be a price in box 2, and if not, what should happen then when initials are in box 1? And what should happen if the user clears box 1?

Linda5579Author
Participating Frequently
March 23, 2020

So from what I found I entered the following under properties; calculate; custom calculation script:

 

event.value = (this.getField("Initial 1").valueAsString=="") ? "" : "Price 1"

I then tried to enter initials in the "Initial 1" box but nothing happens.

Thom Parker
Community Expert
Community Expert
March 24, 2020

This script should have worked to put "Price 1" into the field. 

There must be something else going on. Look in the Console window to see if any errors are reported.

 

You'll find a tutorial on the console here:

https://www.pdfscripting.com/public/Free_Videos.cfm#JSIntro

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often