These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

List item selection problems - drop-down list (switch-case)

Andres
Registered: Jan 18 2010
Posts: 6
Answered

Hi,

I have created three objects - DropDownList1, DropDownList2, TextField1. DropDownList1 has three items: “Selection1”, “Selection2”, “Selection3”. I need to populated the second drop-down list based on a selection from the first drop-down list (it’s done successfully with switch-case statement). In addition TextField1 should show bound value of the second drop-down list.

The problem is that, when I make selection from DropDownList2, some selected items are not displayed correctly. For example, if you chose “Selection2” from DropDownList1 and then “ASBESTOS” from DropDownList2 it displays “ALACHLOR” instead of the selected item “ASBESTOS”. It is hard to explain this in words, you have to try it in my sample form yourself.

Temporary link to my sample *.pdf: http://www.box.net/shared/5kqbl4tj1f

Javascript code:
---------------------
form1.#subform[0].DropDownList1::change - (JavaScript, client)
---------------------
switch(xfa.event.newText)
{
case "Selection1":

break;

case "Selection2":
DropDownList2.rawValue = null;
DropDownList2.clearItems();
TextField1.rawValue = null;
DropDownList2.addItem("ALACHLOR", "[b]1[/b]");
DropDownList2.addItem("ALDRIN", "1");
DropDownList2.addItem("ANTHRACENE", "1");
DropDownList2.addItem("AS AND COMPOUNDS", "5");
DropDownList2.addItem("ASBESTOS", "[b]1[/b]");

break;

case "Selection3":

break;
}

---------------------
form1.#subform[0].DropDownList2::change - (JavaScript, client)
TextField1.rawValue = this.boundItem(xfa.event.newText);
---------------------

I can’t manage to figure out what is the problem, many thanks to anyone who can help me with this issue!

My Product Information:
LiveCycle Designer, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The "boundItem" is the export value of the list item. Try displaying "xfa.event.newText" which is the selected display value.

Have you read this article:
http://www.acrobatusers.com/tutorials/2007/js_list_combo_livecycle/

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Andres
Registered: Jan 18 2010
Posts: 6
Many thanks, Thom!

Now it works well, I just added "this.rawValue = this.xfa.event.newText;" under event change of the "DropDownList2".

The new code is:

form1.#subform[0].DropDownList2::change: - (JavaScript, client)
----------------------------------------------------------------------------
this.rawValue = this.xfa.event.newText;
TextField1.rawValue = this.boundItem(xfa.event.newText);
---------------


Still it's a little strange for me, that in order to get "DropDownList2" to show me the same item what I'm selecting, I have to explicitly command (this.rawValue = this.xfa.event.newText) the "DropDownList2".

Just one peculiar thing more what I have noticed, is that earlier, when I chose display items from DropDownList2 in the same order (alphabetical) as they were displayed, then only every fourth item was display as expected (i.e. the right way). I have also noticed, that such display problem arrises only, when I'm using drop- down lists, which are populated dynamicly with [display and value pairs] by javascript code. At the same time there are no such problems, when I use the same code to populate drop- down list, with only display items (i.e. without display/value pair).
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
All you need is this:

TextField1.rawValue = xfa.event.newText;

I didn't notice before that you have several export values that are identical. This is not allowed. Export values must be unique for each list item. I believe this is the source of your problems.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Andres
Registered: Jan 18 2010
Posts: 6
My greatest thanks!

You are 100% right, this is exactly the source of my problems. I had display problems only with those drop- down list items, which had identical export values. Of course this also means that, I was wrong in my previous post, where I wrote "Now it works well". It's still not working :-(

I need to solve my problem. Can you perhaps suggest, what method could be used in this situations where drop-down list has several identical export values?

Right now, I'm having an idea, that I could place three drop-down list exactly in the same place on a form (in my case in the same cell of a table) and to use IF-THEN statement to operate VISIBLE/INVISIBLE/HIDDEN properties of these lists.

I really hope that there is some other more simpler solution for such situation?

With best regards!
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
There is a very easy solution. Decouple the list box from the non-unique data. Use a generic JavaScript object to map list entries to the values. There is an example of this in the tutorial on Lists.

But why do the export values matter? You are not using them in the code you've asked about here. From what I've seen so far there is no need to even have an export.


Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Andres
Registered: Jan 18 2010
Posts: 6
Everything is working well now, I managed to create unique export values.

thomp wrote:
But why do the export values matter?
I use export values for validation and also these values are important for form fillers as a background information.

Anyway, many-many thanks, I was almost losing my hope :)