Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
Populate a select list based upon another field
System
I would like to populate a select list based upon the selection of one field in DCT, i.e., a user select a country from the list, then we construct the state list by using the selected country and query the DB. I wouldn't mind to use cgi-callout (pop up another screen for user to choose). Any specific example?
Albert
Find more posts tagged with
Comments
Michael
I think the nicest way is to use formAPI. I have done a quick braindump/half worked example below.
Firstly add an event handler for the country field:
IWEventRegistry.addItemHandler("/country", "onItemChange", countryChanged);
Implement your countryChanged function to query the database.
function countryChanged(item) {
// Get the country item
....
// Get the currently selected country from the item
.... (note use both getValue and getOptions to get the text)
// Call your Perl script which will query the database and return the results
var params = new Object();
params.country = currentlySelectedCountry;
IWDatacapture.callServer("/iw-bin/dev/yourDBRequest.ipl", params);
}
Your Perl script queries the database and prints to standard out the required JavaScript to populate yours states droplist and probably redraw.
// Perl script to query database and put results in appropriate format in $result
....
// Output JavaScript which is executed in template
print <<EOT1;
<html>
<head>
<script language="javascript">
var api;
api = parent.getScriptFrame();
newOptions = new Array();
EOT1
print $result;
print <<EOT2;
api.IWDatacapture.getItem("/state").setOptions(newOptions);
api.IWDatacapture.redraw();
</script>
</head>
<body>
</body>
</html>
EOT2
exit;
HTH
Cheers
Michael