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 <abasta...@gmail.com> 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 <m.mirghorb...@gmail.com> 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.

Reply via email to