Purpose
Form should have a dropdown, in which the values are dynamically loaded according to the user’s selection in the preceding control. Solution should avoid writing and maintaining complex DOM manipulation script. Populated values should come from an external source like a Database table of and XML file.
Sample Scenario
User is provided with a Country dropdown. As per his choice, the City dropdown should get populated with Cities under the selected country.
Solution
An external data source will be created out of a relational data table or an xml file. Entries for the City dropdown are filtered using a defined filter.
Step by step walk-through
- Create an xml file as following and save it as Options.xml
<Options>
<Country CountryID="US" CountryName="United States">
<City CityID="LAX" CityName="Los Angeles" />
<CityCityID="SEA"CityName="Seattle"/>
</Country>
<CountryCountryID="CA" CountryName="Canada">
<CityCityID="WPG" CityName="Winnepeg" />
<CityCityID="ONT" CityName="Ontario"/>
</Options>
- Open a new blank InfoPath form in design mode
- Save it as Country-City.xsn
- Go to Tools/DataConnections/Add/RecieveData/XMLDocument/
- SelectOptions.xml file
- Check‘Automatically Retrieve Data’ and click Finish.
Note: This will help you not to carry the Option.xml file anymore.
- Create two Dropdown boxes, named ddCountry and ddCity
- Double-click on ddCountry
- Check ‘Lookup values in a data connection…’
- Select Options in the Data Connection dropdown.
- Click on Entries, select Country, and click OK
- Select Value as CountryID and Name as CountryName
- Apply/OK
- Double-click on ddCity
- Check ‘Lookup values in a data connection…’
- Select Options in the Data Connection dropdown.
- Click on Entries, select City, and click Filter Data/Add
- select City, is equal to, ddCountry (from Select a field or group/Main)
- Press OK 3times
- Select Value as CityID and Name as CityName
- 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 Full Trust option
- Check ‘Sign this form” and create or use a certificate.
Install this certificate in the client computer where you use this form.
Conclusion
This is a simple solution helps to avoid DOM manipulation script, which is complex.
Download the sample