Hi Anthony,
No, it is not called. I tried to define the drop-down menu in a
different way:
form=FORM(SELECT('Iowa City', 'Cedar Rapids',
_id='keyword',_name='City', _onchange="ajax('callback', ['City'],
'target');"))
Note that in this case, the values of the drop-down menu are hard-
coded (I don't know how to get them from a DB in this format). The
ajax function is called perfectly fine in this case. I am confused.
On Feb 6, 1:08 pm, Anthony <[email protected]> wrote:
> Can you use the browser developer tools to see if the Ajax call is getting
> sent?
>
>
>
>
>
>
>
> On Monday, February 6, 2012 1:50:40 PM UTC-5, shartha wrote:
>
> > Thank you so much for the responses.
> > I tried both methods, but none worked for me. I am guessing I have
> > something typed wrongly. With the first method I came up with:
>
> > def index():
> > form = SQLFORM.factory(Field('City', requires=IS_IN_DB(db,
> > 'cities.id', '%(name)s',error_message='Please select a city',
> > zero="Please select a city")),
> > submit_button='Next'
> > )
> > c = form.element(_name='City')
> > c['onchange'] = XML("ajax('callback', ['City'], 'target');")
>
> > if form.process().accepted:
> > session.city = request.vars.City
> > redirect(URL('clients'))
>
> > return dict(form=form)
>
> > def callback():
> > return "Function is working"
>
> > and my view has a <div id="target"> in it. The drop-down menu is
> > showing fine. But the onchange event is not working. =(
>
> > Any ideas?
>
> > On Feb 6, 9:26 am, Anthony <[email protected]> wrote:
> > > 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.