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

change the colour of a text field when text is enter

Community Beginner ,
Jun 29, 2022 Jun 29, 2022

Hello,

I am working on a form and my client has requested that when the user has enter information in the text box that it becomes highlighted. If the user doesn't enter any information the text box stays white

TOPICS
Create PDFs , Edit and convert PDFs , General troubleshooting , How to , JavaScript , PDF forms
1.8K
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 ,
Jun 29, 2022 Jun 29, 2022

You can do it, but it will only change the fill color once you exit the field, not while you're tying in it.

To achieve it use the following as the field's custom Validation script:

 

event.target.fillColor = event.value.length==0 ? color.transparent : color.yellow;

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 ,
Jun 29, 2022 Jun 29, 2022

As 'Validation' script of that field use this:

event.target.fillColor = event.value == "" ? color.white : color.blue;

 

Change color.blue to the color you wish field to be highlighted, note that you can use RGB colors too, for example:

color orange would be - ["RGB", 255/255, 165/255, 0/255]

If you have fields highlight turned on in your preferences you won't be able to see colors when they change, you will need to turn highlight off under preferences-> forms-> uncheck 'Show border hover color for 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 Beginner ,
Jun 29, 2022 Jun 29, 2022

just a quick question because I am not the best at writing code in between  the quotation marks is that where I place the name of text box so example

event.target.fillColor = event.value == "textbox1" ? color.white : color.blue;

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 ,
Jun 29, 2022 Jun 29, 2022
LATEST

The double quotation marks are indicating the field being blank. The code is saying, "when the value of the textbox is blank (""), the color will be white, otherwise the color will be blue (or yellow, or whatever you choose)."

As long as you enter the code into the Custom Validation script area of the textbox itself, you don't actually have to name the field (that is what 'event.target' does for you). You can use the code exactly as @try67  or @Nesa Nurani provided it, changing only the color, if desired.

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