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

Auto-advance Numbers in a Form

New Here ,
Sep 19, 2016 Sep 19, 2016

I have a form where I created 12 different text fields.

I would like to enter a number in the the first field and have each of the subsequent fields auto-advance by 1.  So, for example, if the first number is 61, the last number should be 72.

Thanks for your inputs.

TOPICS
Acrobat SDK and JavaScript , Windows
1.1K
Translate
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

LEGEND , Sep 21, 2016 Sep 21, 2016

Change:

nStart + i

to:

nStart + i - 1

Translate
LEGEND ,
Sep 19, 2016 Sep 19, 2016

What are the field names? You can use a custom validate script for the first field that gets the entered value and sets the other field values, but the script will depend on the names of the 11 subsequent fields.

Translate
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 ,
Sep 20, 2016 Sep 20, 2016

I have them numbered "EXHIBIT NO#0" THROUGH "EXHIBIT NO#11". I can re-name them, of course.

Translate
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
LEGEND ,
Sep 20, 2016 Sep 20, 2016

OK, assuming the first field has a numeric format, its custom Validate script could be:

// Custom Validate script for "EXHIBIT#0" field

(function () {

    // Convert this field's value to a number

    var nStart = +event.value;

    // Set the subsequent field values

    // Set to blank if this field is blank

    for (var i = 1; i <= 11; i += 1) {

        getField("EXHIBIT#" + i).value = event.value ? nStart + i : "";

    }

})();

Translate
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 ,
Sep 21, 2016 Sep 21, 2016

I know how to get to the Validate and enter in a Script, but I've never done it before.

Can I impose on you to break this down a little bit more for someone who hasn't done Scripting before?

Translate
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
LEGEND ,
Sep 21, 2016 Sep 21, 2016

On the Validate tab of the field properties dialog, select the "Run custom validation script" option and paste the script that I provided. The script will be triggered whenever you then change the value of the initial field.

validateScript.png

Translate
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 ,
Sep 21, 2016 Sep 21, 2016

I copied and pasted it into Exhibit #0, and it auto-populated the script into the other Exhibit #1-11.  Is it supposed to do that?

But, when I enter "1" into the field (after closing the Form Editing) it still populated everything as "1" for all fields.

Translate
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
LEGEND ,
Sep 21, 2016 Sep 21, 2016

That means that all of the fields are named the same, but they need to be different. Rename them to something else like: EXHIBIT_1, EXHIBIT_2, EXHIBIT_3, ...EXHIBIT_11, and change that one line of code to:

getField("EXHIBIT_" + i).value = event.value ? nStart + i : "";

Translate
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 ,
Sep 21, 2016 Sep 21, 2016

I feel that I'm following your directions.  Is something not right here?

Form Field.JPG

Translate
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
LEGEND ,
Sep 21, 2016 Sep 21, 2016

You've renamed most of them, but you still need to rename the one that appears in the field list as EXHIBIT#1 to EXHIBIT_1. I'm assuming that the one that appears in the field list as EXHIBIT#0 is the field you want to be the initial field.

You'll also have to rename most of the other fields in the form so that they are unique. Otherwise, they won't behave independently and when you enter a value in one, the other fields that have the same name will get the same value. This is probably not what you want.

Translate
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 ,
Sep 21, 2016 Sep 21, 2016

The other fields (Case No., Plaintiff and Defendant) I actually do want to be all the same.

I corrected/renamed the Exhibit field.  Also, I looked at the coding script and made a couple changes that seemed appropriate, but it still did not populate correctly.Form Field 2.JPG

Translate
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
LEGEND ,
Sep 21, 2016 Sep 21, 2016

Make sure that the only the initial EXHIBIT field has a validation script. Then display the interactive JavaScript console by pressing Ctrl + J and change the value of the initial field. Are there any error messages in the console?

Translate
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
LEGEND ,
Sep 21, 2016 Sep 21, 2016

By the way, your fields are now named like "EXHIBIT NO_2", but the script is expecting field names like "EXHIBIT_2", so you'll have to change one or the other to match.

Translate
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 ,
Sep 21, 2016 Sep 21, 2016

Form Field 3.JPG

Translate
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
LEGEND ,
Sep 21, 2016 Sep 21, 2016

Since your field names are now "EXHIBIT NO_1" through "EXHIBIT NO_12", change that one line of code to:

    for (var i = 2; i <= 12; i += 1) {

Translate
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 ,
Sep 21, 2016 Sep 21, 2016

I just replaced that line with the above.  Still no love....

Form Field 4.JPG

Translate
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
LEGEND ,
Sep 21, 2016 Sep 21, 2016

The script and field names now look correct. In order to trigger the script you have to change the value of the "EXHIBIT NO_1" field. If that doesn't result in the other exhibit fields being auto-populated, then look at the JavaScript console by pressing Ctrl + J to see if any errors are reported.

Translate
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 ,
Sep 21, 2016 Sep 21, 2016

Yay!  Almost there!  The fields changed this time.  But one small issue.  It skips what should be the 2nd number in the sequence.

Form Field 5.JPG

Translate
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
LEGEND ,
Sep 21, 2016 Sep 21, 2016

Change:

nStart + i

to:

nStart + i - 1

Translate
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 ,
Sep 21, 2016 Sep 21, 2016
LATEST

George, you're my hero!!!!

thanks so much for your help!!

Translate
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