Skip to main content
Participant
May 19, 2020
Question

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

  • May 19, 2020
  • 1 reply
  • 498 views

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

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
May 19, 2020

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.

Participant
May 19, 2020

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