Print Page | Close Window

Dynamic Dropdowns

Printed From: Foxit's Planet PDF Forum
Category: Lets Talk PDF
Forum Name: JavaScript
Forum Description: Discussions relating to the use of JavaScript within PDF.
URL: http://forums.planetpdf.com/forum_posts.asp?TID=135
Printed Date: 16 Jul 2019 at 5:12am
Software Version: Web Wiz Forums 11.10 - http://www.webwizforums.com


Topic: Dynamic Dropdowns
Posted By: skowalczyk
Subject: Dynamic Dropdowns
Date 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!!!



Replies:
Posted By: RaeEveMay
Date 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;
}


Posted By: mmazal
Date 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"])



Posted By: dimitri
Date 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


Posted By: wilfred
Date 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?


Posted By: try67
Date 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


Posted By: gkaiseril
Date 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');
}
 


Posted By: wilfred
Date 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


Posted By: try67
Date 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


Posted By: aandi
Date 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.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.10 - http://www.webwizforums.com
Copyright ©2001-2017 Web Wiz Ltd. - https://www.webwiz.net