Hi community I'm having a few problems trying to understand how create a cascading drop down list. I've followed this tutorial -
http://www.web2pyslices.com/slice/show/1526/cascading-drop-down-lists-with-ajax-2 i've managed to adapt it slightly, but i'm having trouble trying to add more tables to the cascade/sequence It is quite difficult for me (a beginner) to suss out the logic behind it. So at the moment i have the code below, what i'm trying to do is return a list of values from the "tax_class" table based selecting results from the "tax_phylum" table *model* db.define_table('tax_kingdom', Field('name')) db.define_table('tax_phylum', Field('name', 'string'), Field('kingdom_id')) db.tax_phylum.kingdom_id.requires = IS_IN_DB(db, db.tax_kingdom.id, '%(name)s') db.define_table('tax_class', Field('name', 'string'), Field('phylum_id')) db.tax_class.phylum_id.requires = IS_IN_DB(db, db.tax_phylum.id, '%(name)s') *Controller* def index(): kingdoms = db().select(db.tax_kingdom.ALL) if request.vars.kingdom_name: phylum_select = db(db.tax_phylum.id == request.vars.kingdom_name).select(db.tax_phylum.ALL) else: phylum_select = db(db.tax_phylum.id == 1).select(db.tax_phylum.ALL) return dict(kingdoms=kingdoms, phylum_select=phylum_select) def phylum(): phylums = db(db.tax_phylum.kingdom_id == request.vars.kingdom_name).select(db.tax_phylum.ALL) result = "" for p in phylums: result += "<option value='" + str(p.id) + "'>" + p.name + "</option>" return XML(result) *view* {{extend 'layout.html'}} <form enctype="multipart/form-data" action="{{URL()}}" method="post"> <select name='kingdom_name' onchange="jQuery('#kingdom_name').empty(); ajax('phylum', ['kingdom_name'], 'phylum_name');"> {{for kingdom in kingdoms:}} <option value="{{=kingdom.id}}" {{=" selected='selected'" if str(kingdom.id)==request.vars.kingdom_name else ""}}> {{=kingdom.name}} </option> {{pass}} </select> <select id='phylum_name' name='phylum_name' > <!-- loop through the index function i --> {{for phylum in phylum_select:}} <option value="{{=phylum.id}}" {{=XML(" selected='selected'") if str(phylum.id)==request.vars.phylum_name else ""}}> {{=phylum.name}}</option> {{pass}} </select> </form> -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.

