Skip to main content
Inspiring
November 7, 2025
Answered

Type between parenthesis, but parenthesis stays

  • November 7, 2025
  • 4 replies
  • 180 views

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)

Correct answer PDF Automation Station

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

 

4 replies

PDF Automation Station
Community Expert
Community Expert
November 7, 2025

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

 

Thom Parker
Community Expert
Community Expert
November 7, 2025

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.  

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participating Frequently
November 7, 2025

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

Thom Parker
Community Expert
Community Expert
November 7, 2025

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. 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Inspiring
November 7, 2025

I found the answer to my own question

 

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