Skip to main content
Participant
March 21, 2025
Question

Start an action when a Text field has a value

  • March 21, 2025
  • 1 reply
  • 183 views

I have been reviewing over so many options and ideas that have solved several answers... but I cannot for the life of me, find what it is I am trying to do.  I have been back and forth with several options, but just cannot get it to work.

 

Scenario:

This is a form for customers to fill out when they may be online and have interest.  Instead of calling in, they can fill out this quick form and get an idea what the cost may be.

 

One line option is similar to this one.

How many oranges would you like to have? ______

Users are to just type a number into a textfield placed where the underline is.  If they type "4", then it should start an action and fill out the "demo" invoice.  This textfield would be called, "txtNumOrng".  Format would be a number.

 

Once this number is typed in, down within the same adobe pdf, we have a "demo" invoice with columns showing "Description", "Qty", "UnitPrice" and "TotalPrice" that should be filled in.  In this scenario:

Description would be oranges, "Qty" would equal the text placed within the textfield "txtNumOrng", etc. etc.  If this txtNumOrng field is emptied, then the entire line within the "demo" invoice would be cleared.

 

This is what I have been tinkering with to get this to maybe work the right way:

---------------------------------------------------------

var txtToDesc = "ORANGES";
var txtToDesc2 = "ORANGES: Cleaned with more description if needed for this line";
var txtOrngUnitPrice = "100";

var cbOranges = this.getField("cbOranges");
var txtNumOrng = this.getField("txtNumOrng");

if (checkbox.value == "100") {
textbox.readonly = false;
}
else
{
textbox.readonly = true;
textbox.value = "";
}

this.getField("3rdLineDescA").value = (event.target.value == "Off")? "" : txtToDesc2;
this.getField("3rdLineQtyA").value = (event.target.value == "Off")? "" : txtNumOrng;
this.getField("3rdLineUPA").value = (event.target.value == "Off")? "" : txtOrngUnitPrice;

----------------------------------------------

Checkbox?  Yes, I have even tried to pass the text field to start a checkbox action and try to have the checkbox to complete the invoice entry.  Close, but not the right way IMHO.  The checkbox is not necessary, but more of a "I have an idea" idea.  Ya'll been there too, don't deny it.

 

Any thoughts on this or other ideas?  You probably need more information so ask away.  Typing it all out here may be more confusing without the questions you need answered.  Thanks ahead of time!

 

1 reply

try67
Community Expert
Community Expert
March 22, 2025

So is your question how to trigger the code? Use the text field's Validation even, like this:

 

if (event.value) {

// code to fill other fields

} else {

// code to clear other fields, if desired

}

Participant
March 24, 2025

Hmm... "custom validation script"?

 

So within Adobe, how is this so different than say the "Actions" of running a JS?

 

Code is one thing.. but where and how you use it within an application can sometimes bother me.  Meaning if I use this same code in the "Action", "Validate" or "Calculate" tabs, it should do what the JS demands.  Obviously, there is more to each tab within the Adobe PDF application.  Wrong?

 

BTW, not complaining... just learning.

try67
Community Expert
Community Expert
March 24, 2025

Which Actions do you mean? Mouse Up/Mouse Down/Enter Field/etc.?

And yes, where the code is placed is crucial to how it will work. The validation event is triggered whenever the user changes the value of that field, which is the most suited for your needs. Calculation, on the other hand, is triggered when the value of any field in the file is changed. That can also work, but it will execute all the time, even when completely other fields are filled-in, which is not necessary in your case.