• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Create Javascript that runs for all form fields

New Here ,
Nov 26, 2019 Nov 26, 2019

Copy link to clipboard

Copied

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 .......

TOPICS
Acrobat SDK and JavaScript

Views

456

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 26, 2019 Nov 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");
	}
}

Votes

Translate

Translate
Community Expert ,
Nov 26, 2019 Nov 26, 2019

Copy link to clipboard

Copied

Using Javascript you can set actions of the fields.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 26, 2019 Nov 26, 2019

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 26, 2019 Nov 26, 2019

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 26, 2019 Nov 26, 2019

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 26, 2019 Nov 26, 2019

Copy link to clipboard

Copied

Where would I put this code?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 26, 2019 Nov 26, 2019

Copy link to clipboard

Copied

It's for a one-time use. You can run it from the JS Console, or even a button field.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 26, 2019 Nov 26, 2019

Copy link to clipboard

Copied

I have added alot of the actions already.  What would be the test for the action?

if (!f.setAction("onBlur")){dothis}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 26, 2019 Nov 26, 2019

Copy link to clipboard

Copied

Not possible. The script can't know if a field already has an action associated with it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 26, 2019 Nov 26, 2019

Copy link to clipboard

Copied

What happens if there is an action already there?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 26, 2019 Nov 26, 2019

Copy link to clipboard

Copied

It will be overwritten by the new code.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 26, 2019 Nov 26, 2019

Copy link to clipboard

Copied

AWESOME!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 26, 2019 Nov 26, 2019

Copy link to clipboard

Copied

LATEST

You just saved me about 4 hours of time.  Thanks very much

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines