Copy link to clipboard
Copied
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.
Change:
nStart + i
to:
nStart + i - 1
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
I have them numbered "EXHIBIT NO#0" THROUGH "EXHIBIT NO#11". I can re-name them, of course.
Copy link to clipboard
Copied
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 : "";
}
})();
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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 : "";
Copy link to clipboard
Copied
I feel that I'm following your directions. Is something not right here?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
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) {
Copy link to clipboard
Copied
I just replaced that line with the above. Still no love....
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Yay! Almost there! The fields changed this time. But one small issue. It skips what should be the 2nd number in the sequence.
Copy link to clipboard
Copied
Change:
nStart + i
to:
nStart + i - 1
Copy link to clipboard
Copied
George, you're my hero!!!!
thanks so much for your help!!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now