Copy link to clipboard
Copied
Hello all. I am trying to create a field in one of my forms using Adobe Acrobat Pro XI. I have a dropdown list of "main" items, and based on what is selected in that list, I want a second dropdown list to give different choices. I have searched and searched and have javascript that I thought might work, but maybe I am have a mistake or I am placing the javascript in the wrong place, becasue it is not working. I know very, very little about javascript, so any help would be so much appreciated.
I am using Adobe Acrobat Pro XI. I added a "new field", and selected "dropdown". The field name is ProvType. The dropdown options are:
Inpatient
Outpatient
Physician
I have the "Commit selected value immediately" selected.The field is not validated. The format is "none." There are no actions or calculations associated with it.
I then created another dropbox, and named it SubProvType. Under Actions, I selected the trigger as Mouse Up, and then selected the Action "Run a JavaScript." I selected the add button, and typed this in the JavaScript editor:
switch (ProvType.rawValue)
{
case "Inpatient":
this.setItems("Hospice,Hospital,Nursing Facility");
break;
case "Outpatient":
this.setItems("Adult Day Center,Home,Other");
break;
case "Physician":
this.setItems("Surgeon,Family Practice,Neurologist");
break;
}
What I want to happen is:
If "Inpatient" is selected, I want the following options to be available in the second dropdown box "SubProvType":
Hospice
Hospital
Nursing Facility
If "Outpatient" is selected, I want the following options to be available in the second dropdown box "SubProvType":
Adult Day Center
Home
Other
If "Physician" is selected, I want the following options to be available in the second dropdown box "SubProvType":
Surgeon
Family Practice
Neurologist
However.... when I close the form editing and try to select a different option in the ProvType field, the SubProvType field remains blank and there are no options available. There are also no errors.
I must be missing something, but I have no idea where to start. Thank you in advance for any help anyone can provide.
Copy link to clipboard
Copied
Use this code as the custom validation script of ProvType (and remove any code you associated with SubProvType):
switch (event.value) {
case "Inpatient":
this.getField("SubProvType").setItems(["Hospice,Hospital,Nursing Facility"]);
break;
case "Outpatient":
this.getField("SubProvType").setItems(["Adult Day Center,Home,Other"]);
break;
case "Physician":
this.getField("SubProvType").setItems(["Surgeon,Family Practice,Neurologist"]);
break;
}
Copy link to clipboard
Copied
Is this an LCD form?
Copy link to clipboard
Copied
Gilad D... no, I am creating the form in Adobe Acrobat XI Pro.
Copy link to clipboard
Copied
Then you have quite a few mistakes in your code. First of all, to access a field you must use the getField method. Also, there's no such property called rawValue. You should use value or valueAsString. Also, the setItems method takes an array of strings as its single parameter, not multiple string parameters.
Copy link to clipboard
Copied
Thanks for your reply Gilad D. The code that I was using, in going back and looking, was for LiveCycle.... I was guessing that it would be the same. I will do some more digging with your suggestions. I understand what you are saying, but I honestly have no idea how to put it all together to make it work. Is there a tutorial that you know of that might help me out? I'm interesting in figuring this out, I just don't know where to start 😕
Copy link to clipboard
Copied
Have a look at these tutorials:
https://acrobatusers.com/tutorials/js_list_combo_livecycle
https://acrobatusers.com/tutorials/list_and_combo_in_lc
On Thu, Oct 30, 2014 at 8:39 PM, aimee_boise <forums_noreply@adobe.com>
Copy link to clipboard
Copied
I am still having no luck. I have read Thom Parker's Programming List and Combo fields part 1 and have tried to follow the AcroForm document example that he used in the tutorial to make my form work, but the tutorial example is so much more complicated than the 2 fields that I need, and I cannot follow it. His documentation is awesome, but I just can't wrap my head around it. I am now guessing that this must not be as simple as adding a JavaScript action to a field in Acrobat 😕 Are there any other suggestions or code that someone might be willing to help me with?
I did find a forum question, Auto-Filling a Drop down List with a Drop down List (JavaScript), that had an answer also by Thom Parker, that stated it would work with something simple:
var oSelListItems = {"aa":[1,2,3,4], "bb":[5,6], "cc":[7,8,9]};
However, I still am unsure where to add this, or if this is all the form will need. (The first part of the tutorial example no longer exists on that site, so I could not follow along.) Does anyone know if this would work for my scenario?
Thanks again in advance for any help and/or coding anyone can pass along.
Copy link to clipboard
Copied
Use this code as the custom validation script of ProvType (and remove any code you associated with SubProvType):
switch (event.value) {
case "Inpatient":
this.getField("SubProvType").setItems(["Hospice,Hospital,Nursing Facility"]);
break;
case "Outpatient":
this.getField("SubProvType").setItems(["Adult Day Center,Home,Other"]);
break;
case "Physician":
this.getField("SubProvType").setItems(["Surgeon,Family Practice,Neurologist"]);
break;
}
Copy link to clipboard
Copied
Gilad D...THANK YOU SO MUCH! With a little modification, this is working perfectly!
I modified the setItems so that they would come up as individual items on the second dropdown list:
switch (event.value) {
case "Inpatient":
this.getField("SubProvType").setItems(["Hospice","Hospital","Nursing Facility"]);
break;
case "Outpatient":
this.getField("SubProvType").setItems(["Adult Day Center","Home","Other"]);
break;
case "Physician":
this.getField("SubProvType").setItems(["Surgeon","Family Practice","Neurologist"]);
break;
}
I can't thank you enough! Now I have this working and I can build from it, adding (many) new main and sub types (there are around 80), and also figure out how to have a "-----" (none) selected, but I am confidant I can do that. Thank you again so much!
Copy link to clipboard
Copied
Just add it as the first item in the list. It will be the default item that
way.
Copy link to clipboard
Copied
I am trying to do something very similar. I am not a script writer at all so I was happy to find this thread. I copied the information from this to try to create by own script and I am running into issues when I copy the information to Adobe. It is not validating. Could you please assist me? I am building a change of curriculum form for the university. I want the student's selection of their NewMajor to Populate the choices they get for the Concentration. When I copied this information into the JavaScript Editor in Adobe Forms I get an Error Message "SyntaxError: invalid switch statement 2: at line 3. Any help would be greatly appreciated.
switch (event.value) {
NewMajor "BA - Communication (BACOMM)":
this.getField("Concentration").setItems(["Select One,None,Mass Communication (MCO1),Theatre (THEA),Communication Studies (MC02)"]);
break;
NewMajor "BA - History (BAHIST)":
this.getField("Concentration").setItems(["Select One,None,Teacher Certification (HIS1)"]);
break;
NewMajor "BBA - Business Administration (BBA-BADM)":
this.getField("Concentration").setItems(["Select One,None,Supply Chain Management (SCM),Hospitality Management (HSMG)"]);
break;
}
Copy link to clipboard
Copied
dbettis2.... Please understand that everything I am about to tell you is ONLY thanks to the help I received from Gilad D. I don't know if this will help you or not, but I want to try and pass it forward.
If what you are looking to do is have two dropdown fields, and the second one (concentration) be a list determined by what was chosen in the first one (newMajor) then this will work, if you are using Adobe Acrobat Pro.
Create a dropdown field and name it newMajor. In the "options" tab. Make sure that you enter all of the items that you want in that list AND that they match the javascript (or this will not work.)
In this case, I believe you want the initial list to be:
- Select One -
BA - Communication (BACOMM)
BA - History (BAHIST)
BBA - Business Administration (BBA-BADM)
After you create the dropdown field and enter all of the options, go to the Validate tab, chose "run custom validation script", then copy and paste the following:
switch (event.value) {
case "- Select One -":
this.getField("Concentration").setItems(["-----"]);
break;
case "BA - Communication (BACOMM)":
this.getField("Concentration").setItems(["- Select One -","None","Mass Communication (MCO1)","Theatre (THEA)","Communication Studies (MC02)"]);
break;
case "BA - History (BAHIST)":
this.getField("Concentration").setItems(["- Select One -","None","Teacher Certification (HIS1)"]);
break;
case "BBA - Business Administration (BBA-BADM)":
this.getField("Concentration").setItems(["- Select One -","None","Supply Chain Management (SCM)","Hospitality Management (HSMG)"]);
break;
}
Then create a second dropdown field, and name it Concentration. Nothing further needs to be done with the second dropdown field (as far as entering options or any javascript.)
It should work. I have created a form using this code and field structure, and it is working. I hope this helps you, if in fact this is what you were trying to do. (I do not know how to attach a file to this post or I would send you the PDF that I made so you could see the fields. If you message me, I can send it to you.)
Copy link to clipboard
Copied
That worked perfectly!!! Thank you so much for the assistance!!
Copy link to clipboard
Copied
I am trying to do something similar; with the first drop down menu being a list of numbers (1-57) and then I want the second drop down menu to give a list of different violation codes that can be chosen. For example If someone chooses #1; I want the second drop down menu to give these options to choose from 2-101.11(A),(B) PIC is present, 2-102.11(A),(B) No P violations or certified manager, 2-102.11(C),(1),(4-16) EHS-Questions & PIC Answers, 2-103.11(A)-(O) PIC duties
I would appreciate any guidance you can give me on this. I have tried using the same steps as you have given, but it keeps giving me a syntax error
Copy link to clipboard
Copied
@aimee_boise Sorry to ressurect such an old thread, but I'd ike to thank you for your clear explanation of the steps you had yourself learned!
It turned out that the problem I'd been having was trying to put the validation script in the second drop down box, not the first one, which I now understand 'pushes' the info into the second drop down, as opposed to simply not displaying the options that apply only to the other options in box 1.
Copy link to clipboard
Copied
Hello,
I am trying to acheive something similar with 3 drop-down menus: L0 determinses values in L1 which determines values in L2.
L0
-Direct
-Indirect
-Misc
L1 (Direct)
-Collection Materials
-Fleet
-Fuel & Chemicals
L2 (Collecion Materials)
-Containers
-Drums
I do not have any script writing skills so detailed explainiantion will be apprecaited. I will be grateful if you coudl share your PDF for me to undertsnad the script.
Copy link to clipboard
Copied
Here's an article that shows the exact steps to create a 2 tiered dropdown dependency and provides an example. The pattern of the 2 combo solution can be easily extended.
If you don't want to work out the scripting yourself, then you should consider hiring a developer.
Copy link to clipboard
Copied
I am trying to do something similar; with the first drop down menu being a list of numbers (1-57) and then I want the second drop down menu to give a list of different violation codes that can be chosen. For example If someone chooses #1; I want the second drop down menu to give these options to choose from 2-101.11(A),(B) PIC is present, 2-102.11(A),(B) No P violations or certified manager, 2-102.11(C),(1),(4-16) EHS-Questions & PIC Answers, 2-103.11(A)-(O) PIC duties
I would appreciate any guidance you can give me on this. I have tried using the same steps as you have given, but it keeps giving me a syntax error
Copy link to clipboard
Copied
This code worked beautifully to populate a second dropdown. The user needs to then be able to select more than one item from the dropdown. I understand you can only choose one item from a dropdown, so I created 2 additional dropdowns so they can select more than one if needed. For example, if they choose Student Success from the main dropdown, my second drop down populate with SC 1, 2 & 3, but I also need the 2 additional dropdown field to populate with the same items. I tried adding additional code at the end of the script for the additional dropdowns field using the different this.getField name, but nothing happens when I click on them. Are you allowed to populate additional dropdowns?
Student Success
SC Strategy 1
SC Strategy 2
SC Strategy 3
Employee Engagement
EE Strategy 1
EE Strategy 2
EE Strategy 3
Copy link to clipboard
Copied
Yes, any number of dropdowns can be populated. The likely issue is an error in the code. In fact, it is always more likely that there is an error in the code than there is some limit, or some problem with Acrobat.
The first thing to do is to check the console window for any reported errors.
You'll find a video here on using the console window:
https://www.pdfscripting.com/public/Free_Videos.cfm#JSIntro
Next, post your code.
And consider starting a new topic. This thread is way too long.
Copy link to clipboard
Copied
I'm attempting to do something similar, but not quite what the original post needed help with. I tried to modify this script, but as I have zero experience working with scripts, it isn't working for me.
I'm trying to build an invoice for set items, so the item description column has a dropdown list of the items we offer. I'd like to be able to choose an item, and then in the next column have the price associated with that item show up. I attempted to change the script so that it looked like this:
switch (event.value) {
case "12x18_Mohawk_100C_Coated":
this.getField("COSTRow1").setItems(["0.15"]);
break;
but I'm not sure how I need to format the COSTRow1 box in order for it to show the price associated with the above script.
Or the above script could be intended solely for an additional dropdown and that's my problem. Again: zero experience. Would love some guidance!
Copy link to clipboard
Copied
Is the cost field a drop-down? If so, why? I think it makes more sense to use a text field, and then you can use this code to populate it with the value and the Format setting will take care of the rest:
this.getField("COSTRow1").value = 0.15;
Copy link to clipboard
Copied
I hope you can help walk me through this process in a little more detail. I am trying to dynamically link two drop down menus in adjacent columns.
In other words, I have 4 major programs in one dropbown list; and, 4 dropdown lists of departments for each program. Once you select a program from the dropdown list, then I want to have the only corresponding dropdown list of departments appear in the adjacent box.
1 Direccion Superior
2 SEE
3 SEAF
4 SET
For the sake of example:
Program1 has 13 Departments
Program 2 has 7 departments
Program 3 has 9 departments
Program 4 has 7 departments
I have seen the prior scripts that you have listed above but i do not know how or where to write this and what steps i need to take.
Thank you in advance.
Julio
Copy link to clipboard
Copied
You can use this tool I've developed for exactly this kind of task: Custom-made Adobe Scripts: Acrobat -- Create Dependent Dropdowns
Copy link to clipboard
Copied
This has been a really helpful thread for trying to get some validation. I am having some trouble extending this out to multiple dropdowns and some help would be awesome.
I am trying to do something a little different with validation based on the primary dropdown selection, feeds into 3 sub dropdown boxes.
Scenario, each site has a different number if buildings,If someone selects wellington, then they get Building one, two and 3, and they have floor 1-10 and room 1-100. if Auckland is selected they have only buildings 1-2 and floor 1-5 and room 1-50 etc...
e.g.
First dropdown (City)
Wellington
Auckland
Christchurch
Second dropdown (Site)
Building 1
Building 2
Building 3
Third dropdown (Floor)
Floor 1
Floor 2
Floor 3
Fourth dropdown (Room)
Room 1
Room 2
Room 3
For the first dropdown I have the starting code as below which will work for the second dropdown, bit I have tried adding other lines to make the third and 4th dropdowns, but it gives me an error saying a ] is missing. Should I just be able to add the following to the original code?:
case "Wellington":
this.getField("Floor").setItems(["- Select One -","None","1","2","3"]);
break;
switch (event.value) {
case "- Select One -":
this.getField("Site").setItems(["-----"]);
break;
case "Wellington":
this.getField("Site").setItems(["- Select One -","None","Building 1","Building 2","Building 3"]);
break;
case "Auckland":
this.getField("Site").setItems(["- Select One -","None","Building 1","Building 2"]);
break;
case "Christchurch":
this.getField("SIte").setItems(["- Select One -","None","Building 1",]);
break;
}