Well, you're doing it wrong. I mean, the way you are calling the ajax function...
ajax('rank', ['department'], 'seafarer_experience_rank'); What that does is calls 'rank' with the argument 'department' and replace the contents of the element whose ID is 'seafarer_experience_rank' with the results. In this case, it's wiping out your: {{if request.vars.department:}} {{for r in ranks:}} {{=OPTION(r.name, _value=r.id)}} {{pass}} {{pass}} And replacing it with the dict that is returned from 'rank'. You probably want the 'rank' function to return your HTML that you want. Or you should use a javascript templating library (such as jqote2) to take your data (returned as a dict) and turn it into html. 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.