To expand on Anthony's post, your first drop down will have a unique id. If nothing else, you can look in the page source for it.
Use the 'live' event, not 'onchange.' Onchange only fires once and your user might change his mind. Likewise, use ajax to repopulate the second dropdown after the change. On Dec 15, 7:58 pm, Anthony <abasta...@gmail.com> wrote: > You can't really pre-populate the field because you don't know the cpu > value until after the user selects the sku. So, you'll have to do this with > JS/jQuery and Ajax on the client side. Use jQuery to detect the sku > selection, and when detected, send an Ajax request to web2py to have it > look up the associated cpu. Check > outhttp://web2py.com/book/default/chapter/10#The-ajax-Functionfor some > ideas. > > Anthony > > > > > > > > On Thursday, December 15, 2011 7:08:04 PM UTC-5, Adi wrote: > > > I'm still trying to resolve my problem, and desperately need someone's > > help :) > > > When I try to add a new sku to a purchase order, I would like to > > prepopulate "CPU" field with the value from db.sku.cpu (determined by a > > dropdown). > > >http://127.0.0.1:8000/test/default/list_purchase_orders/purchase_orde... > > > Is it possible to do this through smartgrid, and how would I do it? Bellow > > is a short version of my code for this... I'm stuck... :( > > > #db.py > > db.define_table('sku', > > Field('sku_number', 'string', label=T('SKU #')), > > Field('description', 'string', label=T('Description')), > > Field('cpu', 'double'), > > Field('note', 'text'), > > format='%(sku_number)s - %(description)s', > > ) > > > db.define_table('purchase_order', > > Field('po_number', 'string'), > > ) > > > db.define_table('po_sku', > > Field('sku_id', db.sku, label=T('SKU #')), > > Field('po_id', db.purchase_order, label=T('Purchase Order > > #')), > > Field('qty', 'integer'), > > Field('cpu', 'double'), > > ) > > > # default.py > > def list_purchase_orders(): > > db.purchase_order.id.readable = False > > > db.purchase_order['_plural'] = 'Purchase Orders' > > > grid=SQLFORM.smartgrid(db.purchase_order, details=True, > > links_in_grid=True, > > maxtextlengths={'purchase_order.po_number':15}, > > maxtextlength=20, > > paginate=20, > > csv=False, > > ui='jquery-ui', > > user_signature=False, oncreate = auth.archive, > > onupdate=auth.archive) > > return dict(grid=grid)