Skip to main content
Participating Frequently
August 28, 2020
Question

Conditional Formatting to Fill a text box color IF a different box has text

  • August 28, 2020
  • 2 replies
  • 2693 views

I want to make a box colored yellow to highlight a signature on a page if there is text in another box on that same page. 

I have put this code in the Text Field Properties > Validate > Run custom validation script

if (event.value= (this.getField("Text_Box_With_Text_if").valueAsString=="")) event.target.fillColor = color.yellow;

else event.target.fillColor = color.transparent;

 

I have the Border color and fill color set to "No Color" in the appearance tab.

What is going wrong?

Thanks in advance.

This topic has been closed for replies.

2 replies

Joe5CBEAuthor
Participating Frequently
August 31, 2020

@try67

What would be the coding for if the current text field has text then change the border color to black.

Else border is transparent.

Nesa Nurani
Community Expert
Community Expert
August 31, 2020

Hi, you can use this code:

if(event.value != ""){
event.target.borderColor = color.black;}
else event.target.borderColor = color.transparent;

Joe5CBEAuthor
Participating Frequently
September 1, 2020

"Hi, you could achive this if you replace text box with image field and input photo with desired opacity, and use script in another field to show/hide image field." 

If I wanted to do this and hide/show an image field based on if a checkmark box is checked what would the code be and where would I insert it?

 

Likes

 
try67
Community Expert
Community Expert
August 28, 2020

Change this:

if (event.value= (this.getField("Text_Box_With_Text_if").valueAsString==""))

To:

if (event.value=="")

try67
Community Expert
Community Expert
August 28, 2020

Or, if you want it to be based on another field's value, then change that line to:

if (this.getField("Text_Box_With_Text_if").valueAsString=="")

Joe5CBEAuthor
Participating Frequently
September 1, 2020

Or you could actually use a comment... Those can be created and edited using a script, too.


So I want to make it so that if this box is checked, the highlight tool shows up. Otherwise, it is not there. Where do I need to go to input the code and what is the code needed?