Skip to main content
Known Participant
Nov 26, 2019 8:22 AM UTC
Answered

Create Javascript that runs for all form fields

I have a form that is about 200 text fields.  Is there a way to use a general onblur / onfocus for all of them?  adding the same javascript for all of them is a pain in the .......

This topic is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
Nov 26, 2019 9:42 AM UTC

Yes, that's possible, using this code:

 

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("OnFocus", " // enter on focus code here");
		f.setAction("OnBlur", " // enter on blur code here");
	}
}

12 replies

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
Nov 26, 2019 9:42 AM UTC

Yes, that's possible, using this code:

 

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("OnFocus", " // enter on focus code here");
		f.setAction("OnBlur", " // enter on blur code here");
	}
}
Translate
blenkhn1Author
Known Participant
Nov 26, 2019 7:02 PM UTC

Is this a one time use code or part of the PDF?

Translate
Bernd Alheit
Community Expert
Community Expert
Nov 26, 2019 9:33 AM UTC

Using Javascript you can set actions of the fields.

Translate
blenkhn1Author
Known Participant
Nov 26, 2019 7:08 PM UTC

To do this is very time intensive as I have over 200 fields on the PDF

Translate