Copy link to clipboard
Copied
Hi there,
I'm trying to create a fillable form in Acrobat Pro where I select a value in dropdown field A, dropdown field B will only display a list of values pertaining to the value in A.
Thanks.
Copy link to clipboard
Copied
Use setItems() to populate dropdown field, here is an example code:
if(event.value == "Item1")
this.getField("Dropdown2").setItems(["Item 1","Item 2","Item 3"]);
else if(event.value == "Item2")
this.getField("Dropdown2").setItems(["Item 4","Item 5","Item 6"]);
else this.getField("Dropdown2").clearItems();
You can also give items an export value like this:
setItems([["Item 1", "1"], ["Item 2", "2"], ["Item 3", "3"]]);
Copy link to clipboard
Copied
You are a genius! That was my first time posting on this forum for help and I did not expect an answer so quickly. I can't thank you enough. This was my first time using JavaScript.
Copy link to clipboard
Copied
Hello,
I am folowing this discussion and thank you for providing solutions. I too have 2 Dropdown lists and based on the choice from the first list, I am trying to set the items (numbers 1-10 or 1-25 or 1-12 etc.). When I tab after selecting the item from first DD1, the second DD2 is populated with the range for previous DD1 choice. I have used the clearItems() as suggested above. How do I clear and reset the correct range for the choice in DD1?
Any help is appreciated. Thank you.
Copy link to clipboard
Copied
if IT-"AOS/Unit Data/Position Data,"Access/Security","Alert/Audit","Assignments","Awards","Benefits","Contracts","Help Desk/CRM/FAQ/KB","IPPS-A INTERNAL ACCESS REQUEST","IPPS-A Training / ELM","Job Data","MILPAY","Mobile App","On/Off Boarding","Orders Framework","Personnel Action Request / PAR","Physical Profiles","Production Support","Profile Management","promotions","R3 Cutover Support","R3 Training RFI","Readiness & Manning (HCM)","Reductions","Reports / Analytics","Restrictions","SICOOP (formerly SIHOL)","SRB","SSI-Cadre and Students ONLY","System Preformance","Talent Management","Trading Partners (Into IPPS-A)","Trading Partners (Out IPPS-A)","User Interface / Homepage","Workflow"
if HR-"AOS/Unit Data/Position Data,"Access/Security","Accessions","Awards","Benefits","Career Management","Change Request","Enhancement Request","Evaluations","HRC Tier 1 Use Only","IPPS-A HR Processes","IPPS-A Knowledge Base","IPPS-A Technical Issues","Job Data","Misrouted Case","Pay & Allowences","Promotions & Selections","R3 Training Rfi","Record Management","SSI-Cadre & Students Only"
Copy link to clipboard
Copied
I cannot get this to work for the life of me. I create the code but my second drop down does not populate the options?
Copy link to clipboard
Copied
You are missing some things and have errors, let's say your second dropdown is named "Dropdown2" as validate script of first dropdown use like this:
var drop2 = this.getField("Dropdown2");
if(event.value == "IT")
drop2.setItems(["AOS/Unit Data/Position Data","Access/Security","Alert/Audit"]);
else
drop2.clearItems();
Copy link to clipboard
Copied
I was using the original code:
if(event.value == "HR Help Center")
this.getField("Category").setItems(["AOS/Unit Data/Position Data","Access/Security","Accessions","Awards","Benefits","Career Management","Change Request","Enhancement Request","Evaluations","HRC Tier 1 Use Only","IPPS-A HR Processes","IPPS-A Knowledge Base","IPPS-A Technical Issues","Job Data","Misrouted Case","Pay & Allowences","Promotions & Selections","R3 Training Rfi","Record Management","SSI-Cadre & Students Only"]);
else if(event.value == "IT Help Center")
this.getField("Category").setItems(["AOS/Unit Data/Position_Data","Access/Security","Alert/Audit","Assignments","Awards","Benefits","Contracts","Help Desk/CRM/FAQ/KB","IPPS-A INTERNAL ACCESS REQUEST","IPPS-A Training / ELM","Job Data","MILPAY","Mobile App","On/Off Boarding","Orders Framework","Personnel Action Request / PAR","Physical Profiles","Production Support","Profile Management","promotions","R3 Cutover Support","R3 Training RFI","Readiness & Manning (HCM)","Reductions","Reports / Analytics","Restrictions","SICOOP (formerly SIHOL)","SRB","SSI-Cadre and Students ONLY","System Preformance","Talent Management","Trading Partners (Into)","Trading Partners (Out)","User Interface / Homepage","Workflow"]);
else this.getField("Category").clearItems();
Nothing populates in my second dropdown named Category
Copy link to clipboard
Copied
Works fine for me.
Where did you put the script?
It should go in the first dropdown in 'Validate'.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Got it! I didnt have a blank option available.
Copy link to clipboard
Copied
Hello, I am gettig a SyntaxError: unterminated string literal 2: at line 3 message that won't let me continue
Copy link to clipboard
Copied
Post your script.
Copy link to clipboard
Copied
Could someone look at this please? I keep getting errors as well but can't seem to get it fixed. Thank you!
if(event.value == "Auto Supplies")
this.getField("Product Child").setItems(["Auto Parts","Body/Paint","Gas/Oil/Additives","Service/Repair","Tires"]);
else if(event.value == "Automotive")
this.getField("Product Child").setItems(["Auto Dealer Assoc","Auto Local Dealers","Auto Manufacturer","Auto Rental","Motorcycle","Recreational vehicle/Boats"]);
else if(event.value == "Beauty & Grooming")
this.getField("Product Child").setItems(["Anti-perspirant/Deodorant","Cosmetics","Fragrance/Cologne","Haircare Supplies","Nail Supplies","Personal Hygiene","Shaving","Skin Care","Soap/Body Wash"]);
else if(event.value == "Beverages")
this.getField("Product Child").setItems(["Beer/Wine","Bottled Water","Cold Beverage","Hot Beverage","Spirits"]);
else if(event.value == Computers")
this.getField("Product Child").setItems(["Hardware","Internet Service Provider","Online Services","Software"]);
else if(event.value == "Education")
this.getField("Product Child").setItems(["Colleges","Day Care/Pre-School","Driving Schools","Private/Online","Public Schools","Trade Schools","Other Education"]);
else if(event.value == "Entertainment")
this.getField("Product Child").setItems(["900#","Amusement Park/Activity Center","Archery/Shooting Venue","Dating Services","Fairs/Festivals","Gallery/Museum","Golf Courses","Home Video","Movie","Sporting Event","Theater/Musical/Concerts"]);
else if(event.value == "Financial")
this.getField("Product Child").setItems(["Accountant/Tax Services","Banks/Loans/Credit Unions","Credit Cards","Credit Counseling","Insurance-Medical/Auto/Other","Investment Services"]);
else if(event,value == "Food Products")
this.getField("Product Child").setItems(["Baked Goods","Breakfast/Cereal","Candy/Gum/Snacks","","Canned/Prepared Food","Condiments","Dairy Products","Desserts","Meat Products","Produce"]);
else if(event.value == "Gaming")
this.getField("Product Child").setItems(["Casinos","Lottery","Online/Fantasy/Sports Betting"]);
else if(event.value == "General Services")
this.getField("Product Child").setItems(["Apartments/Housing/Rental Services","Auction Services","Business Services/Printing","Cable/Satellite Services","Car Wash","Cleaning/Laundry/Uniform Rental Services","Delivery/Food Delivery Services","Event Planner/Vendor","Farming/Agriculture","Health/Fitness","Home Inspection","Landscape/Lawn Care Services","Library","Manufacturing","Mining/Quarrying/Oil Extraction","Moving/Storage","Organizations/Associations/Clubs/Unions","Pest Control Services","Pet Boarding/Grooming","Postal/Shipping","Recycling","Religious Services","Salons/Personal Care","Security/Alarm","Telephone/Cellular","Towing/Hauling","Utilities"]);
else if(event.value == "Government")
this.getField("Product Child").setItems(["Federal Government","Municipal Government","State Governemnt","Health Department"]);
else if(event.value == "Health Care")
this.getField("Product Child").setItems(["Addiction/Behavorial Services","Chiropractor","Cosmetic Surgery","Dentists/Dentures","Doctors","Hospitals/Clinics","Medical Equipment","Optical/Hearing","Paramedics/Ambulances","Physical Therapy/Rehab","Psychiatric","Research/Scrn/Testing","Retirement/Assisted Living/In-Home Care","Weight Control"]);
else if(event.value == "Home Products")
this.getField("Product Child").setItems(["Air Fresheners","Carpet/Floor Covering","Cleaning Supplies","Dishwashing","Drapes/Blinds","Fireplaces","Food Storage","Laundry/Fabric Care","Lawn/Garden","Paint/Wallpaper","Paper Products","Pest Control Products","Pool/Spa","Vacuum/Floor Cleaner","Water Systems"]);
else if(event.value == "Home Improvement")
this.getField("Product Child").setItems(["Closet Systems","Concrete/Paving","Contractors/Builders","Electrical","Fence/Gates","Foundation","Gutters/Siding","Heating and AC","Kitchen/Bath","Painters/Drywall","Plumbing","Restoration","Roofing","Solar","Storm Shelters","Windows/Doors"]);
else if(event.value == "Media")
this.getField("Product Child").setItems(["Books/Newspapers/Magazines","Promo","Radio","Television"]);
else if(event.value == "Pharmaceutica")
this.getField("Product Child").setItems(["Baby Products","Birth Control/Condoms/Family Planning","Dental Supplies","Medicine/Medical Supplies","Optical Supplies","Vitamins/Nutrition"]);
else if(event.value == "Political")
this.getField("Product Child").setItems(["Canidates","Issues/Propositions"]);
else if(event.value == "Professional Services")
this.getField("Product Child").setItems(["Advertising Agency","Attorney/Legal Services","Defense Contractors","Employment/Recruiting","Funeral/Estate","Real Estate","Veterinary Services"]);
else if(event.value == "Restaurants")
this.getField("Product Child").setItems(["Bars/Nightclubs","Casual Dining","Fast Food","Formal Dining","Pizza Restaurants"]);
else if(event.value == "Retail")
this.getField("Product Child").setItems(["Accessories","Appliances","Batteries","Bedding/Linens","Book Stores","Boutique/Speciatly Stores","Business/Equipment","Camera/Photography","Clothing","Convenience/Mini Marts","Department/Discount Stores","Drug Stores","E-Cigs/Tobacco","Electronics","Fabrics/Crafts","Fireworks","Furniture Stores/Mattresses","Grocery Stores","Home Repair/Hardware","Home Decor/Lightening","Jewelry","Liquor Stores","Malls/Shopping Centers","Manufactured/Modular/Prefab Buildings","Music/CD/Video","Music Instrument","Nursery/Florist","Office Supplies","Outdoor/Farming Equipment","Pet Food/Feed Store/Farming Supplies","Shoes","Sporting Goods/Bicycles","Toys/Games"]);
else if(event.value == "Travel")
this.getField("Product Child").setItems(["Airline/Train/Bus","Hotel/Resort","Local Transportation","Tourism/Chamber of Commerce","Travel Agents/Services"]);
else if(event.value == "Various")
this.getField("Product Child").setItems(["Barter","Digital Deal Cards","Direct Response","Network Pass Through","Paid Program"","Per Inquiry","PSA","Tower Rental"]);
else this.getField("Product Child").clearItems();
Copy link to clipboard
Copied
1. In 'Food Products' case, change comma to dot in 'event,value' should be 'event.value'.
2. Also in 'Food Products' case, not an error but you have set empty value: "Candy/Gum/Snacks","","Canned/Prepared Food".
3. In 'Computers' case there is missing quotes: else if(event.value == "Computers").
4. In "Pharmaceutica" case, it is not an error but shouldn't it be "Pharmaceutical" or "Pharmaceuticals"?
5. In 'Various' case you have an extra comma: "Paid Program"",
Copy link to clipboard
Copied
With your exact script, I tried to recreate it.
this if event.value equals "Item1".
getField("Dropdown2").
if (event.value == "Item2") this; else setItems(["Item 1","Item 2","Item 3"]).
getField("Dropdown2").
setItems(["Item 4"," "Item 5"," "Item 6"]); alternatively, this.
getField("Dropdown2").
clearItems(); one has two dropdown menus. Dropdowns 1 and 2
The script that Dropdown2 added.
It appears to only run:
Copy link to clipboard
Copied
I think you try to achieve something like this:
var drop2 = this.getField("Dropdown2");
if(event.value == "Item1")
drop2.setItems(["Item 1","Item 2","Item 3"]);
else if(event.value == "Item2")
drop2.setItems(["Item 4","Item 5","Item 6"]);
else
drop2.clearItems();
Copy link to clipboard
Copied
I am getting an error of "SyntaxError: Illegal Character 1: at line 2" Could I please request assistance, it is occuring on "else if(event.value == “Aviation”)" line?
if(event.value == “Warfare”) this.getField(“Workgroup").setItems([“NPC","BM","CD","CSM","CSMMW","HSM"] );
else if(event.value == “Aviation”)
this.getfield(“Workgroup”).setItems([“ATA”,“ATV”,“AVN”,“A”]);
else this.getfield(event.value == “Engineering”)
this.getfield(“Workgroup”).setItems( ["MT","ET","ETSM","MTSM"] ); .
else if(event.value == “Information Warfare”)
this.getfield(“Workgroup”).setItems( ["CIS","EW","IS","CTS","CTL","CT-MCW"] );
else if(event.value == “Submarines”)
this.getfield(“Workgroup”).setItems( ["AWA","CIS","EW","MT","ET"] );
else if(event.value == “Logistics”)
this.getfield(“Workgroup”).setItems ( ["ML-C","ML-S","ML-C","MED","DEN"] );
else if(event.value == "Personnel")
this.getfield(“Workgroup”).setItems ( ["MPM","MUSN","PTI"] );
Copy link to clipboard
Copied
In this line it should be 'else if' not 'else':
else this.getfield(event.value == “Engineering”)
Also in that line and some others you are using wrong quotes, instead of “” use these "".
Copy link to clipboard
Copied
Thank you for your prompt response, I have corrected as advised however this dose not do anything, to confirm this script is under the first drop down, which then should change the selections available on the drop down below it? (Dose the second drop down need to contain anything or dose it need to contain all possible selection?)
I am also placing the script in Validate, Run custom validation script?
if(event.value == "Warfare")
this.getfield("Workgroup").setItems(["NPC", "BM","CD", "CSM", "CSMMW", "HSM"]);
else if(event.value == "Aviation")
this.getfield("Workgroup").setItems(["ATA", "ATV", "AVN", "A"]);
else if(event.value == "Engineering")
this.getfield("Workgroup").setItems( ["MT", "ET", "ETSM", "MTSM"] );
else if(event.value == "Information Warfare")
this.getfield("Workgroup").setItems( ["CIS", "EW", "IS", "CTS", "CTL", "CT-MCW"] );
else if(event.value == "Submarines")
this.getfield("Workgroup").setItems( ["AWA", "CIS", "EW", "MT", "ET"] );
else if(event.value == "Logistics")
this.getfield("Workgroup").setItems ( ["ML-C", "ML-S", "ML-SC", "MED", "DEN"] );
else if(event.value == "Personnel")
this.getfield("Workgroup").setItems ( ["MPM", "MUSN", "PTI"] );
else this.getField(" ").clearItems();
Copy link to clipboard
Copied
> else this.getField(" ").clearItems();
What dropdown is this?
Copy link to clipboard
Copied
Use:
else if (event.value == “Engineering”)
Copy link to clipboard
Copied
But not with curly quotes, only straight ones will work.
Also, it's getField, not getfield. JS is case-sensitive, remember.
Copy link to clipboard
Copied
I have a similar issue - I'm getting a SyntaxError: missing] after element list 6: at line 7 - this is my code (I have 3 dropdown lists)
if(event.value == "55+"){
this.getField("Calendar").setItems(["General Interest","Health and Wellness"]);
this.getField("Service").setItems(["Book Club","Bridge", "Brain Health Service", "Workshops"]);}
else if(event.value == "Adults"){
this.getField("Calendar").setItems(["Arts - Music","Fitness"]);
this.getField("Service").setItems(["Guitar","Piano Private Lessons", "Dance Fitness", Walking and Running]);}
else if(event.value == "Children"){
this.getField("Calendar").setItems(["General Interest","Fitness"]);
this.getField("Service").setItems(["Book Club","Dance Fitness", "Socials", "Yoga"]);}
else{
this.getField("55+").clearItems();
this.getField("Adults").clearItems();}
Copy link to clipboard
Copied
Use a code editor with syntax highlighting and the error will be very evident:
This screenshot is from Notepad++, which I highly recommend.
Copy link to clipboard
Copied
Thank you for the speedy response. Unfortunately due to my company's security protocols, I'm not able to download any programs onto my computer :(. But I did find where I forgot to add in quotation marks around "Walking and Running" and once I did that, it seems to work. Thank you again for your help 🙂
Copy link to clipboard
Copied
Hi again! So the script above is working, however, my client wants to know if the items shown in Dropdown3 can show different choices based on what is selected in Dropdown1 and Dropdown2. For example, my Dropdown lists are called Category, Calendar and Service. If a user selects "55+" in Category, then Calendar shows choices of "General Interest" and "Health and Wellness", if the user selects "General Interest" then Service Dropdown would show the choices "Book Club" and "Bridge"; if the user selects "Health and Wellness" then Service Dropdown would show "Brain Health Workshop" and "Workshops". Is that even possible?

