Skip to main content
Nov 7, 2025 12:50 PM UTC
Answered

Type between parenthesis, but parenthesis stays

I'm not sure if the title makes sense, but this is what I am trying to do; in the text box, I am typing in a state's abbreviation and need the abbreviation to be in parenthesis, but I don't want to have to put in the parenthesis every time. Is it possible to just type in the two letters but the output of it would switch to the letters be surrounded by the parenthesis? textbox1: I type in IL, output: (IL)

PDF Automation Station
Community Expert
Nov 7, 2025 10:32 PM UTC

The following custom format script is the best solution:

 

if(event.value)
{event.value="("+event.value+")"}

 

https://pdfautomationstation.substack.com/p/custom-format-for-pdf-fields

 

5 replies

PDF Automation Station
Community Expert
Community Expert
Nov 7, 2025 10:32 PM UTC

The following custom format script is the best solution:

 

if(event.value)
{event.value="("+event.value+")"}

 

https://pdfautomationstation.substack.com/p/custom-format-for-pdf-fields

 

Translate
Thom Parker
Community Expert
Community Expert
Nov 7, 2025 10:48 PM UTC

Format or Validation?  Depends on the requirements for the final field value.

  • If this is only for display, then a format script is the only solution.
  • But if the value needs the parentheses, then the Validate (or keystroke) is the only solution.  

 

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participating Frequently
Nov 7, 2025 6:40 PM UTC

Yes that’s totally possible, and how you do it depends on the platform or language you’re using for the text box.

Translate
Thom Parker
Community Expert
Community Expert
Nov 7, 2025 6:15 PM UTC

A Calculation script is a poor (and possibly outright dangerous) solution to this issue.  Never use a calculation script to act on the value entered into a field, because it has the potential to cause an infinate loop. 

 

The correct location for such a script is any of the events that are triggered on data entry into the field. In this instance the Validate event is the best choice since it is triggred after the data is being (but not quite) commited to the field. 

Keep your original solution and make sure to place the code into the Custom Validation Script for the field. 

 

 

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Nov 7, 2025 3:12 PM UTC

I found the answer to my own question

 

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

 

Translate