Another option is to handle it entirely on the client side via jQuery (in a
script tag or a loaded script):
$(function() {
$('select[name="City"]').change(function() {
ajax('function_name', ['City'], 'target_div');
});
});
Anthony
On Monday, February 6, 2012 9:25:29 AM UTC-5, DenesL wrote:
>
> You can use the element function on the created form to locate the
> field (as explained in the book section "Server-side DOM and Parsing"
> in chapter 5) and add the onchange to it:
>
> c = form.element(_name='City')
> c['onchange'] = XML("ajax('function_name', ['City'], 'target_div');")
>
>
>
> On Feb 6, 4:05 am, shartha <[email protected]> wrote:
> > I have a drop-down menu created from a field in my DB using
> > SQLForm.factory. How can I assign an Ajax function to the onchange
> > event of the drop-down menu?
> >
> > The drop-down menu is created from a table called "cities" by:
> >
> > form = SQLFORM.factory(Field('City', requires=IS_IN_DB(db,
> > 'cities.id', '%(name)s',error_message='Please select a city',
> > zero=None)), submit_button='Next')
> >
> > I would like to have an ajax function that has the city selected from
> > the drop-down menu as a parameter and is run every time the selection
> > changes. Something like:
> >
> > onchange="ajax('function_name', ['City'], 'target_div');"
> >
> > Any help would be appreciated.
> >
> > Thanks.