Planet PDF Forum Planet PDF Forum
  New Posts New Posts RSS Feed - Dynamic Dropdowns
  FAQ FAQ  Forum Search   Register Register  Login Login


Hi, welcome to the Foxit Planet PDF Forum. If you have PDF or Adobe Acrobat questions then the right place to ask them is here, in this forum.

Dynamic Dropdowns

 Post Reply Post Reply
Author
skowalczyk View Drop Down
New Member
New Member


Joined: 06 Oct 2011
Points: 15
Post Options Post Options   Quote skowalczyk Quote  Post ReplyReply Direct Link To This Post Topic: Dynamic Dropdowns
    Posted: 06 Dec 2011 at 3:34pm
Hello,
 
I am using Adobe Acrobat X.
 
I am trying to work with 2 dropdowns via an array and setItems().  I can't get it to work.  I am not receiving any errors, but it just won't work.
 
Dropdown1 has the options/export values of:
Music
Movies
TV
 
Depending on the users selection for Dropdown1, certain options will then appear for Dropdown2.
 
If user selects Music in Dropdown1, then a list a songs will appear in Dropdown2.
 
I think the problem is within my array.  I've used arrays before, but not for something like this.
 
In Dropdown1:  Format>Custom>Custom Keystroke script
  var response = this.getField("Dropdown2")
     if (event.changeEx in gItemList)
      response.value = gItemList[event.changeEx]
 
In Document Javascript:
  var gItemList = new Array
   gItemList["Music"] = response.setItems([["Song1","Song1"], ["Song2","Song2"]])
   gItemList["Movies"] = response.setItems([["Movie1","Movie1"], ["Movie2","Movie2"]])
   gItemList["TV"] = response.setItems([["TV1","TV1"], ["TV2","TV2"]])
 
Any help will be greatly appreciated.  Thanks in advance!!!
Back to Top
Sponsored Links


Back to Top
RaeEveMay View Drop Down
New Member
New Member
Avatar

Joined: 31 Jan 2012
Location: Big Bear Lake
Points: 7
Post Options Post Options   Quote RaeEveMay Quote  Post ReplyReply Direct Link To This Post Posted: 31 Jan 2012 at 5:29pm
I'm not sure if this will help but here is an example of a conditional statement based on a drop down field's value.

INS1 is my drop down and ICA120_2 is the event field.

var j = this.getField("INS1");
var k = this.getField("P_D1NAME_D10");
var l = this.getField("C_D1NAME_D10");
var m = this.getField("P_PRI_ADDR_ADDRESS1_D10");
var n = this.getField("C_PRI_ADDR_ADDRESS1_D10");
var o = this.getField("ICA120_2");
var p = this.getField("P_PRI_ADDR_ADDRESS2_D10");
var q = this.getField("C_PRI_ADDR_ADDRESS2_D10");
var s = this.getField("P_PRI_ADDR_CITYSTATEZIP_D10");
var t = this.getField("C_PRI_ADDR_CITYSTATEZIP_D10");

if (j.value==k.value)
{
o.value=m.value+" "+p.value+" "+s.value;
}
if (j.value==l.value)
{
o.value=n.value+" "+q.value+" "+t.value;
}
Back to Top
mmazal View Drop Down
New Member
New Member
Avatar

Joined: 20 Jan 2012
Location: Kitchener, ON
Points: 10
Post Options Post Options   Quote mmazal Quote  Post ReplyReply Direct Link To This Post Posted: 23 Feb 2012 at 1:33pm

I truly hate messing with keystrokes. they never work the way I expect.

To have one dropdown set another I program the main one as normal and then tick the option 'commit immediately'. The second dropdown then has a calculate that says

if (getField("maincombo").value == 1) event.target.setitems(["item1", "item2", "item3"])

else event.target.setItems(["item4", "item5", "item6"])

Back to Top
dimitri View Drop Down
New Member
New Member


Joined: 15 Jul 2011
Points: 7
Post Options Post Options   Quote dimitri Quote  Post ReplyReply Direct Link To This Post Posted: 23 Feb 2012 at 9:01pm
Take a look at this tutorial on Programming List Fields-

http://acrobatusers.com/tutorials/programming-list-and-combo-fields-in-acrobat-and-livecycle-forms

Hope this helps,

Dimitri
WindJack Solutions
www.pdfscripting.com
www.windjack.com
Back to Top
wilfred View Drop Down
New Member
New Member
Avatar

Joined: 23 Sep 2014
Points: 2
Post Options Post Options   Quote wilfred Quote  Post ReplyReply Direct Link To This Post Posted: 23 Sep 2014 at 1:25am
Has anyone had success with this way of creating dependent / dynamic dropdowns? I'm not a programmer so apologies for my lack of knowledge.

I'm getting errors with the following script

if (getField("1_2_COHIProfiles").value == "354-5XXX Siltex Ultra High") event.target.setitems(["135", "160", "185"])
if (getField("1_2_COHIProfiles").value == "354-4XXX Siltex High") event.target.setitems(["125", "150", "175"])
else event.target.setItems(["100", "125", "150"])

Error that comes up is:

Acrobat EScript Built-in Functions Version 11.0
Acrobat SOAP 11.0
SyntaxError: missing ) after condition
1:
SyntaxError: missing ) after condition
1:
SyntaxError: missing ) after condition
1:
SyntaxError: missing ) after condition
1:
SyntaxError: missing ) after condition
1:
TypeError: getField("maincombo") is null
1:Field:Calculate
SyntaxError: missing ) after condition
1:
SyntaxError: missing ) after condition
1:
TypeError: event.target.setitems is not a function
1:Field:Calculate
ReferenceError: changePrimaryBox_1_2_COHIProfiles is not defined
1:Field:Validate
TypeError: event.target.setitems is not a function
2:Field:Calculate
TypeError: event.target.setitems is not a function
2:Field:Calculate
TypeError: event.target.setitems is not a function
2:Field:Calculate
TypeError: event.target.setitems is not a function
2:Field:Calculate
TypeError: event.target.setitems is not a function
2:Field:Calculate
TypeError: event.target.setitems is not a function
2:Field:Calculate
TypeError: event.target.setitems is not a function
2:Field:Calculate
TypeError: event.target.setitems is not a function
2:Field:Calculate
TypeError: event.target.setitems is not a function
2:Field:Calculate
TypeError: event.target.setitems is not a function
2:Field:Calculate
TypeError: event.target.setitems is not a function
1:Field:Calculate
TypeError: event.target.setitems is not a function
1:Field:Calculate
TypeError: event.target.setitems is not a function
1:Field:Calculate
TypeError: event.target.setitems is not a function
1:Field:Calculate
TypeError: event.target.setitems is not a function
1:Field:Calculate
TypeError: event.target.setitems is not a function
1:Field:Calculate
TypeError: event.target.setitems is not a function
2:Field:Calculate
TypeError: event.target.setitems is not a function
2:Field:Calculate

Can anyone tell me what I'm doing wrong?
Back to Top
try67 View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Points: 628
Post Options Post Options   Quote try67 Quote  Post ReplyReply Direct Link To This Post Posted: 23 Sep 2014 at 7:55pm
JS is case-sensitive. The correct name of the function in question is setItems, not setitems.
- Acrobat Expert - Contact me personally at try6767@gmail.com
Check out my custom-made scripts website: http://try67.blogspot.com
Back to Top
gkaiseril View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Location: USA
Points: 4106
Post Options Post Options   Quote gkaiseril Quote  Post ReplyReply Direct Link To This Post Posted: 23 Sep 2014 at 11:49pm
Exactly what are you trying to do?
 
Where is this script located?
 
You might want to look carefully at the logic for the "if" statements. If the first condition is met,
 
if (getField("1_2_COHIProfiles").value == "354-5XXX Siltex Ultra High") event.target.setitems(["135", "160", "185"])
 
The second block of code will run and the else option will set the values.
 
Try the following code and observe what happens as you make each selection.
 
console.show(); console.clear();
event.target.clearItems();
if (getField("1_2_COHIProfiles").value == "354-5XXX Siltex Ultra High") {
event.target.setItems(["135", "160", "185"])
console.println('Ultra High');
}
if (getField("1_2_COHIProfiles").value == "354-4XXX Siltex High") {
 event.target.setItems(["125", "150", "175"])
console.println('High');
} else {
event.target.setItems(["100", "125", "150"])
console.println('default');
}
 
Back to Top
wilfred View Drop Down
New Member
New Member
Avatar

Joined: 23 Sep 2014
Points: 2
Post Options Post Options   Quote wilfred Quote  Post ReplyReply Direct Link To This Post Posted: 29 Sep 2014 at 10:15am
thanks guys, 
I'm just trying to create a dependable dropdown. I'm adding this script to the calculate tab of the second dropdown as per the instructions from a previous contributor.

I tried your suggestion and can see that it's executing the first command then the default one, which overrides the first. 

The other thing i notice when i take the else option out is that the dependency works but when I select from the second dropdown it reverts to the first option in the list. How can I stop this happening?

Thanks for your help
Back to Top
try67 View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Points: 628
Post Options Post Options   Quote try67 Quote  Post ReplyReply Direct Link To This Post Posted: 29 Sep 2014 at 10:21am
Add the word "else" before the second if-statement.

So it will be something like this:

if (...) {

} else if (...) {

} else {


}
- Acrobat Expert - Contact me personally at try6767@gmail.com
Check out my custom-made scripts website: http://try67.blogspot.com
Back to Top
aandi View Drop Down
Senior Member
Senior Member


Joined: 07 Jul 2011
Points: 18358
Post Options Post Options   Quote aandi Quote  Post ReplyReply Direct Link To This Post Posted: 29 Sep 2014 at 10:22am
A common cause of multiple ifs being triggered is using = instead of ==

if ( a = 1 ) do something ;
if ( a = 2 ) do something else ;
if ( a = 3 ) do something else again ;

In this case all three of something, something else and something else again will run.
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.10
Copyright ©2001-2017 Web Wiz Ltd.

This page was generated in 0.047 seconds.