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

Multiple Duplicate Drop Down Menus, Populating Multiple Text Boxes on Sequential Lines

Community Beginner ,
Mar 27, 2024 Mar 27, 2024

I am rebuilding an existing form to add functionality to the fillable areas.  The section I am interested in has 8 lines, each starting with "Type of Marking 1", which is where the user makes the initial selection from a drop-down menu.  Once done, two following boxes on the line, "Contract Item #" and "Units" will auto-fill with predetermined values; a Custom option allows custom entry in all fields.

 

Here is a shot of the form for clarification:

Screenshot1.pngexpand image

 

 

The code I used is below, and worked during the initial build and testing of the form on Line 1.  Then, once I copied the drop down menu, renamed the boxes to "Type of Marking 1a", "Type of Marking 1b", etc, and changed the code to reference the targeted text boxes on each line, only the menu and text boxes on the final line of the form are working.  All the others show the default message to select a type and won't update the text boxes to the correct values when an option is selected in the relevant drop down menu. 

 

I thought this might be a factor of the variable I had declared in the code, so I changed the variable to match the particular name of the drop down menu it will rely upon for input (dropdownValue for the first one, all the way down to dropdownValueG for the final working drop down/text boxes).   Nothing changed.  I've searched for what I'm doing wrong, and have hit all around it, but haven't found the solution I need.

The code used in each of the drop down menus is below (I cut it short here because there are about sixty options with minor variations, but it is the same aside from text box identifiers and the declared variable name for each of the lines of menus and boxes). In this case, this is the example from the final working menu, but the other boxes are the same aside from the values above that I did a Find/Replace All on for each Line in the form:

 

var dropdownValueG = this.getField("Marking Type 1g").value;

switch(dropdownValueG) {
//default used as the "Custom" option to allow custom input to drop down and text boxes
default:  

break;
//Initial choice in the menus
case "--Select--":
	this.getField("Contract Item #8").value = "Select Type First"
	this.getField("Units 8").value = "Select Type First"
break;

case 'TYPE A PVMT LINE MRKG 4"':
	this.getField("Contract Item #8").value = "704SD20-0001"
	this.getField("Units 8").value = "LF"
break;

case 'TYPE A PVMT LINE MRKG 6"':
	this.getField("Contract Item #8").value = "704SD20-0002"
	this.getField("Units 8").value = "LF"
break;

//Lots more options here

case 'TEMP. PVMT MRKG TY. D, CL. III, 24"':
	this.getField("Contract Item #8").value = "512SD20-0065"
	this.getField("Units 8").value = "LF"
break;

}

 

TOPICS
Create PDFs , Edit and convert PDFs , How to , JavaScript , Modern Acrobat , PDF , PDF forms
798
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
1 ACCEPTED SOLUTION
Community Expert ,
Mar 27, 2024 Mar 27, 2024

So, besides the syntax errors, the script location needs to be changed. 

Start by reading these articles:

https://acrobatusers.com/tutorials/change_another_field/

https://www.pdfscripting.com/public/List-Field-Usage-and-Handling.cfm

 

All JavaScript code is run in an event, all of it in every app, not just Acrobat.  JavaScript is event driven.

So if the code is in the "Custom Calculation Script" then it is being run by the "Calculate" event.  The Acobat JS reference has a diagram that shows the order of field event processing.  This is good stuff to know. 

 

Since this code is setting the values of other fields based on a selection in the dropdown, the code should be placed in an event script in the dropdown that is triggered when the selection takes place.  A very good location for this is the Custom Validation script. 

You must also rewrite this script to use the event object to access the selection value. 

This is a really simple change. 

 

switch(event.value)

...

}

 

That's it.  

 

 

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

View solution in original post

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
Community Expert ,
Mar 27, 2024 Mar 27, 2024

So this code is being run from some event in the dropdown named "Marking Type 1g"? 

If this is correct, then in which event script on the dropdown is it placed?

Are any errors reported in the Console Window (ctrl-j)?

 

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

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
Community Beginner ,
Mar 27, 2024 Mar 27, 2024

The code is being used in the Custom Calculation Script area of the drop down menu properties boxes; "Marking Type 1g" is the name of the particular drop down menu that the script is looking at to determine what output it sends to the two text boxes, if any.  The only event should be when the box is selected and an option in the menu is chosen, it will then have the two text boxes display the corresponding data, unless it is the Custom (default) case, in which case the inputs in the drop down and the two text boxes can be customized. 

 

I've received no errors when placing the code into the custom Validation or Calculation Script areas (the only ones I had received prior to this were relatex to syntax errors), and it works if there is only one instance of a drop down and the two boxes (like on the first line of the area I've created them, refer to the image I uploaded).  It's only when I copied the drop down menu to the other lines of the form section and renamed the text boxes it would manipulate in the scripts that all but the last line (the G menu box) stopped performing as expected. 

 

In my tests, it's always just the last line (menu plus two text boxes) that works, no matter how many there are.  

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
Community Beginner ,
Mar 27, 2024 Mar 27, 2024

Actually, I was wrong; I thought you meant when saving the scripts, because I had received some errors initially due to syntax; there are errors being reported by the JavaScript debugger:

 


SyntaxError: missing ] after element list
1:
SyntaxError: missing ] after element list
1:
SyntaxError: missing ] after element list
1:
SyntaxError: missing ] after element list
1:
SyntaxError: missing ] after element list
1:
SyntaxError: missing ] after element list
1:
SyntaxError: missing ] after element list
1:
SyntaxError: missing ] after element list
1:
SyntaxError: unterminated string literal
1:
SyntaxError: unterminated string literal
1:
SyntaxError: unterminated string literal
1:
SyntaxError: unterminated string literal
1:
SyntaxError: unterminated string literal
1:
SyntaxError: missing ] after element list
1:
SyntaxError: unterminated string literal
1:
SyntaxError: syntax error
1:Console:Exec
undefined
SyntaxError: syntax error
1:Console:Exec
undefined
SyntaxError: syntax error
1:Console:Exec
undefined
SyntaxError: syntax error
1:Console:Exec
undefined
undefined
undefined
undefined
undefined
SyntaxError: unlabeled break must be inside loop or switch
1:Console:Exec
undefined
SyntaxError: missing ] after element list
1:
SyntaxError: missing ] after element list
1:
SyntaxError: syntax error
281:

 

Admittedly this is the first time I've ever dealt with scripting in Acrobat, and it's been a few years since I've done much in the way of coding, so this is a new territory for me.

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
Community Expert ,
Mar 27, 2024 Mar 27, 2024

So, besides the syntax errors, the script location needs to be changed. 

Start by reading these articles:

https://acrobatusers.com/tutorials/change_another_field/

https://www.pdfscripting.com/public/List-Field-Usage-and-Handling.cfm

 

All JavaScript code is run in an event, all of it in every app, not just Acrobat.  JavaScript is event driven.

So if the code is in the "Custom Calculation Script" then it is being run by the "Calculate" event.  The Acobat JS reference has a diagram that shows the order of field event processing.  This is good stuff to know. 

 

Since this code is setting the values of other fields based on a selection in the dropdown, the code should be placed in an event script in the dropdown that is triggered when the selection takes place.  A very good location for this is the Custom Validation script. 

You must also rewrite this script to use the event object to access the selection value. 

This is a really simple change. 

 

switch(event.value)

...

}

 

That's it.  

 

 

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

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
Community Beginner ,
Mar 29, 2024 Mar 29, 2024
LATEST

This appears to be working exactly as intended!  I'll know for sure after some wider testing, but I think this has solved my problem. 

 

Thank you very much for your assistance on this!  

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