Skip to main content
first.officer
Inspiring
November 26, 2020
Question

Highlight (fill colour) in fields when duplicate number value entered on a form....

  • November 26, 2020
  • 1 reply
  • 510 views

Hi,

I have a form with 6 pages, and each page has around 80 fields on each (all fields named "NUMBER_PAGEX.X.XX" (the 'X''s obviously being different for each field). In each of these fields I am entering a 4 or 5-digit number.

 

Is there a way with script (Document Level?) that would (say, fill color 'RED') all the relevant fields that have duplicated numbers in them?.

 

Thanks....

This topic has been closed for replies.

1 reply

ls_rbls
Community Expert
Community Expert
November 26, 2020

You can use a document level script like the example below. In my example below, I  created a function named "numberPage()".

 

As you can observe, I also declared my variables, in which variable "g" represents  "NUMBER_PAGEX.X.XX" as the parent field that will be used in the getArray() method..

 

Just change the parent field name  to whatever needs to be applied in the children fields

 

 

 

function numberPage() {

var g = this.getField("NUMBER_PAGE1.1");

var a = g.getArray();

for (i =0; i < a.length; i++) { 

if ( (event.target.name !== a[i].name) && (event.target.value !== a[i].value) ) event.target.fillColor = color.transparent;

if ( (event.target.name == a[i].name) && (event.target.value == a[i].value) ) event.target.fillColor = color.red;

 }
}

 

 

And just call the function from the fields that you want this event to happen. To do so just place the line below as custom calculation script:

 

 

numberPage();

 

 

In the script avbove I am using as template  some of the guidance found in the Adobe Acrobat SDK  JavaScript™ for Acrobat® API Reference

ls_rbls
Community Expert
Community Expert
November 26, 2020

NOTE:  The script above is not throwing any errors in the console but is acting out a little bit on my end. 

 

Let's say that I change the number value on 3 out of 4 children fields. The field that I don't clear remains highlighted. I am not sure if this is a condition  that you want or if you also want to add some sort of resetForm() method in the mix.