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

Change one textbox based on whether another textbox includes certain characters

New Here ,
Jul 16, 2019 Jul 16, 2019

Copy link to clipboard

Copied

Thanks in advance for everyone's help. I'm using Pro 11.

I'm creating a document template where I need certain textboxes to change based on whether a specific box contains certain text, but where there is still other text in the box. For example, if the primary textbox contains "2019-PR-123" I would like a separate box to return "Product", but if the box contains "2019-LM-123" I would like the separate box to return "Labor". But I want the return values to be only based on whether the primary box contains the "PR" or "LM" irrespective of what the other numbers are.

I've searched and searched and can't seem to find a simple way to do this. And I'm easily able to achieve the result of the primary textbox contains only the "PR" or "LM" using an if/then based on the value of the primary box, but I need it to do an if/then based not on the value of the box but whether the box includes certain text within the large text.

TOPICS
Acrobat SDK and JavaScript

Views

294

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 , Jul 16, 2019 Jul 16, 2019

This kind of thing is usually done using a Regular Expression.

You can use this code as the custom calculation script of the second text field:

var s = this.getField("Text1").valueAsString; // insert actual field name

if (/PR/.test(s)) event.value = "Product";

else if (/LM/.test(s)) event.value = "Labor";

else event.value = "";

Votes

Translate

Translate
Community Expert ,
Jul 16, 2019 Jul 16, 2019

Copy link to clipboard

Copied

This kind of thing is usually done using a Regular Expression.

You can use this code as the custom calculation script of the second text field:

var s = this.getField("Text1").valueAsString; // insert actual field name

if (/PR/.test(s)) event.value = "Product";

else if (/LM/.test(s)) event.value = "Labor";

else event.value = "";

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
New Here ,
Jul 16, 2019 Jul 16, 2019

Copy link to clipboard

Copied

LATEST

This exactly what I needed, thank you. I think my two problems was that I wasn't using valueAsString for the source textbox, and I didn't realize you could do a /RegEx/.test(s), I kept incorrectly trying to do the test as a standalone function.

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