Dynamically populating more than one field using xml data biding

72 views
Skip to first unread message

Loralon

unread,
Dec 31, 2008, 5:22:05 AM12/31/08
to Adobe LiveCycle Developers
Hi All,

I have the following code that works fine to dynaically populate a
second drop-down list2 from a choice in drop-down list1 using xml data
biding.

var tempString = "xfa.record." + this.boundItem(xfa.event.newText);
var oItems = xfa.resolveNode(tempString);
var nItemsLength = oItems.nodes.length;

myinfo.page1.state.clearItems();
myinfo.page1.state.rawValue = null;

for (var nItemCount = 0; nItemCount < nItemsLength; nItemCount++)
{
myinfo.page1.state.addItem(oItems.nodes.item(nItemCount).value);
}

Here is my xml file

<?xml version="1.0" encoding="UTF-8"?>
<myinfo>
<country/>
<countries>
<item uiname="United States" token="US"/>
<item uiname="South Africa" token="SA"/>
<item uiname="Australia" token="AU"/>
</countries>
<state/>
<AU>
<item>Australian Capital Territory</item>
<item>New South Wales</item>
<item>Northern Territory</item>
<item>Queensland</item>
<item>South Australia</item>
<item>Tasmania</item>
<item>Victoria</item>
<item>Western Australia</item>
</AU>
<US>
<item>California</item>
<item>New York</item>
<item>Texas</item>
<item>Michigan</item>
<item>North Carolina</item>
<item>South Carolina</item>
</US>
<SA>
<item>Eastern Cape</item>
<item>Free State</item>
<item>Gauteng</item>
<item>KwaZulu-Natal</item>
<item>Limpopo</item>
<item>Mpumalanga</item>
<item>Northern Cape</item>
<item>North-West</item>
<item>Western Cape</item>
</SA>
</myinfo>

I have two questions:

1) I want to be able to structure my xml in a way that I can populate
a third drop-down list3 from a choice in list2. I need to know how to
to include the different capital cities of the states in my xml data
so that they can get populated in list3 from a selection in list2;

2) And be able to script the third list3 to get dynamically populated
from a choice in list2.

Thanks in advance for your help.

Dave Venance

unread,
Jan 3, 2009, 1:42:08 AM1/3/09
to Adobe LiveCycle Developers
I would do this pretty much the same way, only instead of looking for
the country code (AU, US, SA), Look for the state. So your XML would
start to get a bit big as you would have to have a separate node for
every state with it's capital. For example, if you chose US in the
first drop down, and California in the second drop down, the capital
of California I believe is Sacremento so your XML file would have a
new node like:

<California>
<item>Sacremento</item>
</California>

And you would have some script for the 3rd drop-down list like:

var tempString = "xfa.record." + this.boundItem(xfa.event.newText);
var oItems = xfa.resolveNode(tempString);
var nItemsLength = oItems.nodes.length;
myinfo.page1.capital.clearItems();
myinfo.page1.capital.rawValue = null;
for (var nItemCount = 0; nItemCount < nItemsLength; nItemCount++)
{
myinfo.page1.capital.addItem(oItems.nodes.item(nItemCount).value);
}

But I am a little confused as there will only ever be a single capital
for each state, and you can only select one country and one state, so
why would you need a 3rd drop-down list for a single item representing
the capital. I am sure that I am not understanding something here so
perhaps you can clarify.

Dave

Loralon

unread,
Jan 3, 2009, 9:43:07 AM1/3/09
to Adobe LiveCycle Developers
Thank you very much Dave for this answer.

In fact what I need is to have the following result on my form:

1) Select in list1 say US;
2) List2 get populated with states and I then select California. By
selecting in List2, list3 get populated with the corresponding capital
Sacramento;
3) List has the correct value that I need.

I will try as per suggestion and revert with the result otherwise I
will share my sample data for further work.

Thank you.

E. Loralo

unread,
Jan 7, 2009, 10:56:36 AM1/7/09
to Adobe LiveCycle Developers
Good morning Paul, Dave et All,

I have the attached PDF and xml document that are working fine. My only problem now is to be able to adjust the XML with the information for the respective cities of each state so that when a country is selected in list1 (country) the corresponding states are populated in list2 (state) and once a state is selected in list2 automatically list3 (cities) gets populated with the corresponding cities.

So my problem is that I don't know how to expand the xml document by adding the cities with the correct specifications so that they become child node of the states.

Hope someone can help me here.

Loralon
countries2.pdf
countries2.xml
Reply all
Reply to author
Forward
0 new messages