Dropdown list of cascades
I am working on a web application and am trying to code a form with two dropdowns. The list in the second dropdown will depend on the selection from the first. The task itself is not too difficult, except that after the first selection, I need to make a database call to pull the data for the second dropdown. Here I am experiencing difficulties. Both lists are actually populated from the database.
I am working on this in a python script and am trying to do it with javascript onChange function. The web application is built in Zope, and page templates can be python scripted option.
a source to share
you will need to use a combination of Ajax and javascript. Your dropdown's Onchange event is called by a javascript function. This javascript function will make an ajax request to the python script which will actually hit the database and return you a response in a javascript variable. With this javascript variable you can edit the DOM and set the html of the second selection block.
see if u can get some hint from this: http://www.satya-weblog.com/2007/04/dynamically-populate-select-list-by.html
a source to share
This is exactly what I did. Below is the javascript function I ran into. OnChange, I call getOptions and pythonScript creates a second dropdown. I can pass in a parameter to get the data I need for this dropdown. Thanks!
function getOptions() {
var code = 'code=' + $("dropdown1").getValue();
var myAjax = new Ajax.Updater('dropdown2', './pythonScript', { method: 'get', parameters: code });
}
a source to share