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

Can the color of text be changed based on the what the text field ends with?

New Here ,
Jan 16, 2017 Jan 16, 2017

I am trying to change the color of the text based on what the text field ends with.

For example:

"Rewards Price $9.96" - Orange

"Sale Price 9.97" - Red

If the text box ends in .96 it automatically turns the text orange, but if it ends in anything else it ends in red.

Is this possible?

TOPICS
PDF forms
6.7K
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
Community Expert ,
Jan 16, 2017 Jan 16, 2017

Sure. You can use something like this as the field's custom validation script to achieve it:

if (/\.96$/.test(event.value)) event.target.textColor = ["RGB", 1, 0.66, 0];

else event.target.textColor = ["RGB", 1, 0, 0];

Edit: fixed code.

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
Community Expert ,
Jan 16, 2017 Jan 16, 2017

Sure. You can use something like this as the field's custom validation script to achieve it:

if (/\.96$/.test(event.value)) event.target.textColor = ["RGB", 1, 0.66, 0];

else event.target.textColor = ["RGB", 1, 0, 0];

Edit: fixed code.

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 ,
Jan 17, 2017 Jan 17, 2017

I pasted the code, adjusted to color to CMYK and added the colors needed, but the text turned black and doesn't change at all...

if (/\.96/.test(event.value)) event.target.textColor = ["CMYK", 12, 60, 98, 1]; 

else event.target.textColor = ["CMYK", 18, 92, 100, 8];

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 ,
Jan 17, 2017 Jan 17, 2017

You should not change code unless you know what you're doing... First of all, put back the dollar sign where it was. It's not used as such. It's an indicator that the string appears at the end of the text.

The values of a Color object in Acrobat JS are from 0 to 1, not from 0 to 255, as you might be used to.

So divide your current values by 255 to get the correct results.

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 ,
Jan 17, 2017 Jan 17, 2017

Thank you very much!

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 ,
May 14, 2020 May 14, 2020
LATEST

Hello I am struggling to do the code for adobe.

 

The drop down box is mag 58

the two answers are either:

Not Complete (Which I want red) &

Complete (Which I want green)

can someone please help me 

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