Skip to main content
Herubu
Participant
Aug 16, 2017 8:12 AM UTC
Answered

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

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 is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
Aug 16, 2017 8:50 AM UTC

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();");

    }

}

2 replies

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
Aug 16, 2017 8:50 AM UTC

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();");

    }

}

Translate
Herubu
HerubuAuthor
Participant
Aug 17, 2017 2:35 AM UTC

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

Translate