script to ask user click a form field then change the field

May 19, 2020

Copy link to clipboard

Copied

Folks,

 

Does any one have a sample javascript code which

1. Ask user to click a text field.

2. Script get the name of the text field which user clicked.

3. Input something into the text field.

 

Thank you for your help.

--AL

TOPICS
Acrobat SDK and JavaScript

Views

163

Likes

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

script to ask user click a form field then change the field

May 19, 2020

Copy link to clipboard

Copied

Folks,

 

Does any one have a sample javascript code which

1. Ask user to click a text field.

2. Script get the name of the text field which user clicked.

3. Input something into the text field.

 

Thank you for your help.

--AL

TOPICS
Acrobat SDK and JavaScript

Views

164

Likes

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
May 19, 2020 0
May 19, 2020

Copy link to clipboard

Copied

There's no way to do that with just a single script. You'll need to attach a script to the On Focus event of each field in the file to be able to detect which field they selected.

Likes

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
Reply
Loading...
May 19, 2020 0
May 19, 2020

Copy link to clipboard

Copied

Thanks for your time. 

I am a beginner, I just form SOME form fields in my pdf.

My  temperary fix is like this:

 

function formatThis()
{
   var fldName = event.target.name;
   var fld = this.getField( fldName );
   fld.alignment = 'right';
   fld.setAction("Format", "AFNumber_Format(0, 0, 0, 0, '', true);");
   app.beep(0);
   app.alert(' formated field: ' + fldName,3);
}

var fldCnt =0 ;
var textCnt = 0 ;
var selTextCnt = 0;
for ( var i=0; i < this.numFields; i++) {
    fldCnt += 1;
    var f = this.getField(this.getNthFieldName(i));
    f.setAction("MouseUp", " ");
    if ( f.type == 'text' ){
        textCnt += 1;
        f.setAction('MouseUp', 'formatThis()' );
    }
console.println( 'field cnt='+ fldCnt ) ;
console.println( 'text cnt='+ textCnt );
console.println( 'text sel='+ selTextCnt );

 

Likes

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
Reply
Loading...
May 19, 2020 0