Skip to main content
Herubu
Participant
August 16, 2017
Answered

adding a function to all fields in a document (blur and focus)

  • August 16, 2017
  • 1 reply
  • 918 views

Hi,

I've got a simple function that I have added to the 'DocumentJavascripts' in Acrobat in order to change the style of a field.  I know that for a single field, I can use the 'blur' and 'focus' triggers to run it.

But seeing as I need to apply this function to most of the fields in the PDF, is there an easier way of doing this?   Is there a document wide event listener that would work? 

I don't think this is important, but just in case the function I'm using is:

function Blurfield()

{

    V=this.getField(event.targetName);

    if (V.value.length==0)

    {

        V.borderStyle = border.s;

        V.fillColor = color.transparent;

        V.strokeColor = color.transparent;

    }

}

Many Thanks,

Herb

This topic has been closed for replies.
Correct answer try67

There's no "global event listener", but you can use a simple script to do it. I assume you want to apply it to text fields, right?

If so, you can use this code from the JS Console to do it:

for (var i=0; i<this.numFields; i++) {

    var f = this.getField(this.getNthFieldName(i));

    if (f==null) continue;

    if (f.type=="text") {

        f.setAction("OnBlur", "Blurfield();");

    }

}

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
August 16, 2017

There's no "global event listener", but you can use a simple script to do it. I assume you want to apply it to text fields, right?

If so, you can use this code from the JS Console to do it:

for (var i=0; i<this.numFields; i++) {

    var f = this.getField(this.getNthFieldName(i));

    if (f==null) continue;

    if (f.type=="text") {

        f.setAction("OnBlur", "Blurfield();");

    }

}

Herubu
HerubuAuthor
Participant
August 17, 2017

Thanks for that.  I was hoping there was a global event listener that would just resolve it easily, but I guess not.