One more thing - I've seen people have issues with this time and again on this list. You aren't the first person to think of doing this. Look for a good recipe on web2pyslices which does what you want. There are quite a few.
http://www.web2pyslices.com/slice/show/1467/cascading-drop-down-lists-with-ajax On Tuesday, June 18, 2013 10:39:51 AM UTC-7, lesssugar wrote: > > I'm building a cascading dropdown lists. I use web2py ajax function to do > it. My code: > > select 1 (parent): > > <select class="generic-widget" id="seafarer_experience_department" > name="department" > onchange="jQuery('#seafarer_experience_rank__row').show('fast');ajax('rank', > ['department'], 'seafarer_experience_rank');"> > {{=OPTION('-- Choose department --', _value="")}} > {{for d in departments:}} > {{=OPTION(d.name, _value=d.id)}} > {{pass}} > </select> > > select 2 (child): > > <select class="generic-widget" id="seafarer_experience_rank" name="rank"> > {{if request.vars.department:}} > {{for r in ranks:}} > {{=OPTION(r.name, _value=r.id)}} > {{pass}} > {{pass}} > </select> > > controller function: > > def rank(): > > ranks = db(db.rank.department_id == request.vars.department).select( > db.rank.id, db.rank.name, orderby=db.rank.name) > > return ranks > > Ajax function calls *rank *function and passess value of the currently > selected option in *department *select (parent). Then, the function > assigns DAL query to *ranks *and returns it. > > The thing is that *ranks *is a string when returned and the FOR loop in > the select 2 is ommited. An example result code of the select 2 looks like > this after ajax function's done it's job: > > <select class="generic-widget" id="seafarer_experience_rank" name="rank"> > "rank.idrank.name137Chief Cook138Chief Steward139Cook > Assistant140Messman136Second Cook141Steward" > </select> > > So it LOOKS like a Row object but it's a string obvioulsy - and I can't > get any Row data out of it (r.name, r.id). > > Begging for help here :) > > > > -- --- 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/groups/opt_out.

