Skip to main content
bev_s
Inspiring
August 28, 2023
Answered

Is it possible to jump to a specific empty field

  • August 28, 2023
  • 1 reply
  • 1093 views

I am trying to derive a means to have a button that will jump to a specific empty field. Example: I have a series of date fields that will be entered by the user. I would like to create a button that will jump to the first empty date field. Is this possible with a script and would such a script work in Reader without security issues? Thank you!

This topic has been closed for replies.
Correct answer Thom Parker

Hi Thom, yes they are in order and there are 32 date fields (Date1_af_date throug Date32_af_date). Thank you!


Here's the modified code. Notice the only change is the "nNumFields" parameter, which is now set to 32.

var nNumFields = 32, oFld;
for(var i=1;i<=nNumFields;i++)
{
    oFld = this.getField("Date" + i + "_af_date");
    if(oFld.valueAsString == "")
    {
       oFld.setFocus();
       break;
    }
}

 

Note that the code does not contain any error checking, so if an expected field name does not exists the code will just fail at the point that name comes up.  

 

1 reply

try67
Community Expert
Community Expert
August 28, 2023

What are the names of these date fields? And yes, it can be done using a script, and it will work in Reader without any security issues.

bev_s
bev_sAuthor
Inspiring
August 28, 2023

That is great to hear! The date field names are "Date1_af_date" "Date2_af_date" , etc. Thank you for your help!

Thom Parker
Community Expert
Community Expert
August 28, 2023

Given the naming convention, we'll also need to know the number of date fields in order to get the script correct.

We'll also need to know the order of the fields. I'm assuming that "Date1_..." is first, followed by "Date2_...", etc. 

 

So here's the script:

 

var nNumFields = 10, oFld;
for(var i=1;i<=nNumFields;i++)
{
    oFld = this.getField("Date" + i + "_af_date");
    if(oFld.valueAsString == "")
    {
       oFld.setFocus();
       break;
    }
}

         

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often