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

Type between parenthesis, but parenthesis stays

Explorer ,
Nov 07, 2025 Nov 07, 2025

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)

TOPICS
Edit and convert PDFs , JavaScript , PDF , PDF forms
71
Translate
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
1 ACCEPTED SOLUTION
Explorer ,
Nov 07, 2025 Nov 07, 2025

I found the answer to my own question

 

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

 

View solution in original post

Translate
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
Explorer ,
Nov 07, 2025 Nov 07, 2025

I found the answer to my own question

 

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

 

Translate
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
New Here ,
Nov 07, 2025 Nov 07, 2025

You can do that with a simple custom calculation script in the text box. Try this:

  1. Right-click the text field → Properties → Calculate → Custom calculation script

  2. Paste this code:

    if (event.value) {
      event.value = "(" + event.value.replace(/[()]/g, "") + ")";
    }

This will automatically wrap whatever you type (like IL) in parentheses, even if you forget to add them yourself.

Translate
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 ,
Nov 07, 2025 Nov 07, 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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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 ,
Nov 07, 2025 Nov 07, 2025

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

Translate
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 ,
Nov 07, 2025 Nov 07, 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

 

Translate
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 ,
Nov 07, 2025 Nov 07, 2025
LATEST

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

Translate
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