Alex,
Thanks. I thought based on the book that the 2nd argument of ajax was
passing the values to request.vars.variable. I pasted some of the
code from the book below for reference (http://web2py.com/book/default/
chapter/10?search=ajax#The-ajax-Function). Based on this I originally
had the code below in test_chg. Am I mistaken about what the 2nd
argument is? Also, regarding your suggestion, could you tell me how
to identify the selected item so that I can pass as an args/vars in
the URL as you recommended?
def one():
return dict()
def echo():
return request.vars.name
{{extend 'layout.html'}}
<form>
<input id="name" onkeyup="ajax('echo', ['name'], 'target')" />
</form>
<div id="target"></div>
def test_chg
firm=request.vars.firmdrop
strats = db(db.firmstrat.firm_id==firm).select()
options=[]
for strat in strats:
options.append(strat.strat_id.name)
return DIV(*options).xml()
On Nov 8, 9:37 pm, Alex <[email protected]> wrote:
> 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