Skip to main content
Known Participant
November 26, 2019
Answered

Create Javascript that runs for all form fields

  • November 26, 2019
  • 2 replies
  • 1127 views

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 has been closed for replies.
Correct answer try67

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

2 replies

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
November 26, 2019

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");
	}
}
blenkhn1Author
Known Participant
November 26, 2019

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

Bernd Alheit
Community Expert
Community Expert
November 26, 2019

Using Javascript you can set actions of the fields.

blenkhn1Author
Known Participant
November 26, 2019

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