How are you passing the value in the request.vars?
I'm going to guess that on your AJAX call in the _onChange handler,
you want to specify the parameters. You can do something like:
- ajax( '{{=URL(c='controllerName',f='test_chg',
args=request.args(0))}}', ['firmdrop'],'target' )
You can pass whatever you want in args. If you have values in
request.vars, you should be able to access then like:
- request.vars.variableName
On Nov 7, 9:11 pm, oneroler <[email protected]> wrote:
> I'm trying to learn to use the ajax functionality and am having
> trouble getting it to work correctly. I am trying to use a dropdown
> of firms to show the related strategies. Currently this doesn't
> return anything to the div, but I do know that the onchange is
> working. It seems like the request.vars.values()[0] is not returning
> anything. Any help would be appreciated and also any pointers if
> there is a way to do this better differently. Below is my code.
>
> I have based this on this
> messagehttp://groups.google.com/group/web2py/browse_thread/thread/4a6149ddcb....
>
> <<default.py>>
> def test():
> firms = db(db.firm).select()
> return dict(firms=firms)
>
> def test_chg():
> firm=request.vars.values()[0]
> strats = db(db.firmstrat.firm_id==firm).select()
> options=[]
> for strat in strats:
> options.append(strat.strat_id.name)
> return DIV(*options).xml()
>
> <<test.html>>
> {{extend 'layout.html'}}
> {{=SELECT(_id='firmdrop',
> _onChange="ajax('test_chg',['firmdrop'],'target');",
> *[OPTION(firms[i].name,_value=str(firms[i].id)) for i in
> range(len(firms))]
> )}}
> <div id="target"></div>
>
> Thanks,
> Sam