Still isn't clear to me what you are doing. It seems to me that you should use a separate function to return your Options. I would suggest studying the Components section of the book. Use the web2py LOAD to get the Options from a separate function.
On Monday, 17 June 2013 01:16:46 UTC+1, lesssugar wrote: > > Furthermore... strange. If I print the request.vars.dpt somewhere in the > 'add_experience' function, the value is printed in the terminal every time > I select an option the first drop-down. > > However, If I return this in the same function: > > ... > ranks = db(db.rank.department_id == request.vars.dpt).select(orderby=db. > rank.name) > > return dict(ranks=ranks) > > and then check if 'ranks' exists in my view - I get False... > > Do I need an Ajax call to somehow achieve my goal? > > On Monday, June 17, 2013 1:35:51 AM UTC+2, lesssugar wrote: >> >> Yes, I checked: the load function is being triggered and *dpt* variable >> is being set in the function every time I select an option from the first >> drop-down. >> >> The respective view fragment: >> >> <div class="w2p_fw"> >> <select class="generic-widget" id="seafarer_experience_rank" >> name="rank"> >> {{=result}} >> </select> >> </div> >> >> (The HTML is fixed just for now, I've cut the dynamic code to test the >> auto-populating only...) >> >> Not sure if I get the part about rendering "a complete page layout", >> though, but it's a secondary issue for at this point. >> >> >> On Monday, June 17, 2013 12:47:57 AM UTC+2, villas wrote: >>> >>> Hmm I'm not sure you have given enough info. Anyhow: >>> >>> Check in Firebug whether the load function is being triggered. >>> Place print statements in your function to test that the variables are >>> being set. >>> Bear in mind that "return dict(...)" will render a complete page >>> layout. I wonder if that is what you want? >>> Check out the SELECT and OPTION helpers. >>> >>> >>> On Sunday, 16 June 2013 23:10:12 UTC+1, lesssugar wrote: >>>> >>>> I need to auto-populate my 'ranks' drop-down based on the value >>>> selected in the 'department' one. >>>> >>>> This is my script: >>>> >>>> <script> >>>> $("#department").change(function() { >>>> $("#ranks").load("?dpt=" + $("#department").val()); >>>> }); >>>> </script> >>>> >>>> As you can see, I pass *dpt *var to my current function. This is its >>>> code: >>>> >>>> def add_experience(): >>>> >>>> ranks = db(db.rank.department_id == >>>> request.vars.dpt).select(orderby=db.rank.name) >>>> >>>> result = "" >>>> >>>> for r in ranks: >>>> result += "<option value='" + str(r.id) + "'>" + r.name + >>>> "</option>" >>>> >>>> >>>> return dict(result=XML(result)) >>>> >>>> When I select a value in the first drop-down, a request is being sent >>>> to [controller]/add_experience?dpt=[value selected]. However the second >>>> drop-down does not populate with respective data - it's empty. I'm clearly >>>> missing something. Any help? >>>> >>>> -- --- 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.