javascript for sequential fields within a pdf

New Here ,
Jun 14, 2018

Copy link to clipboard

Copied

I am trying to find a javascript that will allow all of the fields in my form to populate in sequential order. I have 10 fields on the PDF and I would like them to be numbered sequentially based off of the first field. Any help would be greatly appreciated.

TOPICS
Acrobat SDK and JavaScript, Windows

Views

428

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

1 Correct Answer

Adobe Community Professional , Jun 15, 2018
BarlaeDC Adobe Community Professional , Jun 15, 2018
Hi,Assuming the fields are numerically ordered ( Field1, Field2, Field3), and that Field1 is the starting field you could use script something likevar startFieldValue = this.getField("Field1").value;for ( var i = 2; i < 10; i++){     startFieldValue++;    this.getField ("Field" + i).value = startFieldValue;}This will add 1 to the value of Field1, and then push that value to the next field in the sequence.The code could probably be added to the validate function of "Field1".Note: there is no chec...

Likes

Translate

Translate
Jump to answer Jump to answer
Adobe Community Professional ,
Jun 15, 2018

Copy link to clipboard

Copied

Hi,

Assuming the fields are numerically ordered ( Field1, Field2, Field3), and that Field1 is the starting field you could use script something like

var startFieldValue = this.getField("Field1").value;

for ( var i = 2; i < 10; i++)

{

     startFieldValue++;

    this.getField ("Field" + i).value = startFieldValue;

}

This will add 1 to the value of Field1, and then push that value to the next field in the sequence.

The code could probably be added to the validate function of "Field1".

Note: there is no checking that the user actually entered a number in the field, which may be required if you haven't applied any validation to the field.

Hope this helps

Malcolm

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
Jun 15, 2018

Copy link to clipboard

Copied

You need to write a custom JavaScript action to perform this task and this would require knowing your actual field names. There are a number of ways to accomplish this.

I would use the "On Blur" action so only after one exits the field the next 9 named fields are updated.. The script could look something like:

// array of field names to populate;

var aFieldNames = new Array("Field.1", "Field.2", "Field.3", "Field.4", "Field.5", "Field.6", "Field.7", "Field.8", "Field.9");

for(var i = 0; i < aFieldNames.length; i++) {

     // to to i field in array set value equal to this field value plus array index + 1;

     this.getField(aFieldNames).value = Number(event.value) + i + 1;

} // field name loop;

The above code does not require and systemic field naming convention, but could easily be modified to support such a naming system. Also the fields are only updated when the first field's value is changed. By using the array of the field names, the script is easily scalible and only requiring the names of the fields to be changed and the script automatically adjust the number of fields to process based on the number of field names entered.

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Engaged ,
Jun 15, 2018

Copy link to clipboard

Copied

I am curious why use the On blur event rather than just the validate event of the first field?

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
Jun 15, 2018

Copy link to clipboard

Copied

That field is executed after the validation event and before the next field in the array of field to be processed is processed. It also allows for the UI validation to be used without having to write special code.

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
kjellcam71 AUTHOR LATEST
New Here ,
Jun 15, 2018

Copy link to clipboard

Copied

Thank you. This worked great!

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more