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

Script that Triggers if Part of Value is Matched

Engaged ,
Jan 09, 2018 Jan 09, 2018

Copy link to clipboard

Copied

I'd like to write a script that matches specific text in part of the field value but not all of it. Is there a way to script that?

The logic would be if the field CONTAINS this specific text, change the text color. If not, keep the text color as black.

Here's what I've tried (tried in both validation and format script with no luck):

if(event.value >= "(T)") {

event.textColor = color.red;

}

else {

event.textColor = color.black;

}

Any suggestions?

TOPICS
Acrobat SDK and JavaScript , Windows

Views

547

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 , Jan 09, 2018 Jan 09, 2018

If you want to check whether this string is anywhere within the value, use this:

if (event.value.indexOf("(T)")!=-1) {

Votes

Translate

Translate
Engaged ,
Jan 09, 2018 Jan 09, 2018

Copy link to clipboard

Copied

If I change "event" to the defined doc level variable, It simply changes to red regardless. I want it to only change if "(T)" is present in the 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
Community Expert ,
Jan 09, 2018 Jan 09, 2018

Copy link to clipboard

Copied

You're using the wrong operator. ">=" means "larger than or equal to", which doesn't apply to strings.

Replace it with "==".

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
Community Expert ,
Jan 09, 2018 Jan 09, 2018

Copy link to clipboard

Copied

LATEST

If you want to check whether this string is anywhere within the value, use this:

if (event.value.indexOf("(T)")!=-1) {

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