Skip to main content
New Participant
October 11, 2016
Answered

How do you highlight a field if it's empty?

  • October 11, 2016
  • 2 replies
  • 2875 views

I want to highlight or color a field when it's empty, how do you do it?

I've been trying out this formula but I think it's not correct because there's a Syntax Error:

var a1 = this.getField("FirstN");

if (a1.value == null)

{

a1.style.backgroundColor = "yellow";

}

This topic has been closed for replies.
Correct answer try67

You have quite a lot of errors there... Try this code (as the field's custom validation script):

event.target.fillColor = (event.value=="") ? color.yellow : color.transparent;

2 replies

Bernd Alheit
Adobe Expert
December 17, 2020

Not all is possible in Acrobat Reader for iOS or Android:

https://www.adobe.com/devnet-docs/acrobatetk/tools/Mobile/iosapi/index.html 

try67
try67Correct answer
Adobe Expert
October 11, 2016

You have quite a lot of errors there... Try this code (as the field's custom validation script):

event.target.fillColor = (event.value=="") ? color.yellow : color.transparent;

Participating Frequently
December 16, 2020

This works great in Acrobat Pro, but the field colors won't change in Acrobat reader which is were most users fill out the form. Is there a way to code this in Pro so that the field colors will change in Acrobat reader?

try67
Adobe Expert
December 16, 2020

It will work exactly the same in Reader. If you don't see it working then make sure to disable the fields highlighting in the application.