Introduction
Assume that a form needs to have a drop down list whose values are dynamically loaded dependent on the user's selection in another control and the solution should avoid problems with writing and maintaining a complex DOM manipulation script. Assume that the values for the drop down list should come from an external source like a database table or an XML file.
This document will go into the Indecomm Knowledge Base repository.
Sample Scenario
The user is presented with a Country drop down list. Depending on his choice, the City drop down list should be populated with Cities that are in the selected country.
Solution
An external data source will be created to access a relational data table or an XML file. Entries for the City drop down are filtered using a defined filter.
Step by step walk-through
- Create an XML file as follows and save it as Options.xml
<?xml version="1.0" encoding="utf-8" ?>
<Options>
<Country CountryID="US" CountryName="United States">
<City CityID="LAX" CityName="Los Angeles" />
<City CityID="SEA" CityName="Seattle" />
</Country>
<Country CountryID="CA" CountryName="Canada">
<City CityID="WPG" CityName="Winnepeg" />
<City CityID="ONT" CityName="Ontario" />
</Country>
</Options>
- Open a new blank InfoPath form in design mode
- Save it as Country-City.xsn
- Go to Tools | Data Connections | Add | RecieveData | XMLDocument
- Select the Options.xml file
- Check Automatically Retrieve Data and click Finish.
Note: This will allow you not to reload the Option.xml file. - Create two Drop down boxes, named ddCountry and ddCity
- Double-click on ddCountry
- Check Lookup values in a data connection…
- Select Options in the Data Connection drop down.
- Click on Entries, select Country, click OK
- Select Value as CountryID and Name as CountryName
- Select Apply | OK
- Double-click on ddCity
- Check Lookup values in a data connection…
- Select Options in the Data Connection drop down.
- Click on Entries. Select City then click FilterData | Add
- Select City, is equal to,and ddCountry from Select a field or group | Main
- Press OK 3 times
- Select Value as CityID and Name as CityName
- Select Apply | OK
- We’re done..! Preview the form.
Note: If you would like to publish this form to public, you need to remove the security restrictions.
- Go to Menu | Tool | Forms Options | Security
- Uncheck Automatically determine security.
- Check the Full Trust option
- Check Sign this form and create or use a certificate.
Install this certificate on the client computer where you will use the form.
Conclusion
This simple solution helps to avoid using a DOM manipulation script, which is complex.
Contact
For any further information or queries contact me at firozozman@hotmail.com
My Blog: www.firozozman.com