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

Auto populate text field based on input in other field

Community Beginner ,
Mar 20, 2020 Mar 20, 2020

Copy link to clipboard

Copied

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!

TOPICS
Acrobat SDK and JavaScript

Views

1.9K

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 , Mar 24, 2020 Mar 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

Votes

Translate

Translate
LEGEND ,
Mar 20, 2020 Mar 20, 2020

Copy link to clipboard

Copied

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?

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 ,
Mar 23, 2020 Mar 23, 2020

Copy link to clipboard

Copied

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.

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 ,
Mar 23, 2020 Mar 23, 2020

Copy link to clipboard

Copied

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Mar 24, 2020 Mar 24, 2020

Copy link to clipboard

Copied

I tried it again today and it does in fact bring in literally the words price1 vs the value entered in the price1 text field.  Do you know how I can get it to pull the value vs the actual words?

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 ,
Mar 24, 2020 Mar 24, 2020

Copy link to clipboard

Copied

LATEST

Here's the working script:

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

 

Notice that "getField()" is used to get the field object, and then the "value" property of the field object. 

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

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 ,
Mar 24, 2020 Mar 24, 2020

Copy link to clipboard

Copied

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

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 ,
Mar 24, 2020 Mar 24, 2020

Copy link to clipboard

Copied

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

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 ,
Mar 24, 2020 Mar 24, 2020

Copy link to clipboard

Copied

You're welcome, happy to help.

 

Would you mind marking my answer as correct?

 

It means a world to me .

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