Cheers, I want to autopost a form that uses form_remote_tag whenever the user chooses something from the drop-down menus. My form looks like this: <%= form_remote_tag(:update => "update_div", :url => { :action => :top_flop }, :loading => "Element.show(''top-flop-indicator'')", :complete => "Element.hide(''top-flop-indicator'')", :html => { :id => ''top_flop_form'', :name => ''top_flop_form''} ) %> The selects look like this: <select name="region" onChange="document.top_flop_form.submit()"> <option value="bla">bla</option> ... </select> The onChange eventhandler works, so when the user chooses another region, the form gets submitted. The problem is that the form submits by "normal" HTTP POST and not by the AJAX update function of protoype. So the whole page gets reloaded instead of just reloading a div. It seems like the "onsubmit=Ajax.update..." for the form (so the result of form_remote_tag) is not called by the document.top_flop_form.submit() stuff? Any hints on thow to autpost the form with AJAX on a change of the drop-downs? Thanks, Jonathan -- Jonathan Weiss http://blog.innerewut.de
Assuming you have a submit button like: <submit_tag :id="the_button"> you could do: <select name="region" onChange="document.top_flop_form.the_button.click()"> This should work, though there is probably another way, more railish.. Bogdan On 9/6/05, Jonathan Weiss <jw-eM0Q5iXcOashFhg+JK9F0w@public.gmane.org> wrote:> > Cheers, > > > I want to autopost a form that uses form_remote_tag whenever the user > chooses something from the drop-down menus. > > My form looks like this: > > > <%= form_remote_tag(:update => "update_div", > :url => { :action => :top_flop }, > :loading => "Element.show(''top-flop-indicator'')", > :complete => "Element.hide(''top-flop-indicator'')", > :html => { :id => ''top_flop_form'', > :name => ''top_flop_form''} > ) %> > > The selects look like this: > > <select name="region" onChange="document.top_flop_form.submit()"> > <option value="bla">bla</option> > ... > </select> > > The onChange eventhandler works, so when the user chooses another region, > the form gets submitted. The problem is that the form submits by "normal" > HTTP POST and not by the AJAX update function of protoype. > > So the whole page gets reloaded instead of just reloading a div. > > It seems like the "onsubmit=Ajax.update..." for the form (so the result of > form_remote_tag) is not called by the document.top_flop_form.submit() > stuff? > > Any hints on thow to autpost the form with AJAX on a change of the > drop-downs? > > > Thanks, > Jonathan > > -- > Jonathan Weiss > http://blog.innerewut.de > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
I think that best way is to use observer_field helper methods for things like this. When you use no frequency it will be event based what is if I got it right what you want. Hope it helps. On 9/6/05, Bogdan Ionescu <bogdan.ionescu@gmail.com> wrote:> Assuming you have a submit button like: > <submit_tag :id="the_button"> > > you could do: > <select name="region" > onChange="document.top_flop_form.the_button.click()"> > > This should work, though there is probably another way, more railish.. > > Bogdan > > > > On 9/6/05, Jonathan Weiss <jw@innerewut.de> wrote: > > Cheers, > > > > > > I want to autopost a form that uses form_remote_tag whenever the user > > chooses something from the drop-down menus. > > > > My form looks like this: > > > > > > <%= form_remote_tag(:update => "update_div", > > :url => { :action => :top_flop }, > > :loading => "Element.show('top-flop-indicator')", > > :complete => "Element.hide('top-flop-indicator')", > > :html => { :id => 'top_flop_form', > > :name => > 'top_flop_form'} > > ) %> > > > > The selects look like this: > > > > <select name="region" onChange="document.top_flop_form.submit()"> > > <option value="bla">bla</option> > > ... > > </select> > > > > The onChange eventhandler works, so when the user chooses another region, > > the form gets submitted. The problem is that the form submits by "normal" > > HTTP POST and not by the AJAX update function of protoype. > > > > So the whole page gets reloaded instead of just reloading a div. > > > > It seems like the "onsubmit=Ajax.update..." for the form (so the result of > > form_remote_tag) is not called by the document.top_flop_form.submit () > > stuff? > > > > Any hints on thow to autpost the form with AJAX on a change of the > > drop-downs? > > > > > > Thanks, > > Jonathan > > > > -- > > Jonathan Weiss > > http://blog.innerewut.de > > > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
> Assuming you have a submit button like: > <submit_tag :id="the_button"> > > you could do: > <select name="region" onChange="document.top_flop_form.the_button.click()"> > > This should work, though there is probably another way, more railish..This works, thanks!> > BogdanJonathan -- Jonathan Weiss http://blog.innerewut.de
Jonathan Weiss wrote:> <select name="region" onChange="document.top_flop_form.submit()">This is OT, but isn''t "document.top_flop_form.submit()" incorrect? Shouldn''t it be "document.forms[''top_flop_form''].submit()"? I''m not sure of the correct answer here - can someone enlighten me? -- Alex
> Jonathan Weiss wrote: >> <select name="region" onChange="document.top_flop_form.submit()"> > > This is OT, but isn''t "document.top_flop_form.submit()" incorrect? > Shouldn''t it be "document.forms[''top_flop_form''].submit()"? I''m not > sure of the correct answer here - can someone enlighten me?document.top_flop_form.submit() works on so far, that the form gets submitted. Only the AJAX magic does not work then... Jonathan -- Jonathan Weiss http://blog.innerewut.de
Also in FF? Or just IE? Ronny On 9/6/05, Jonathan Weiss <jw@innerewut.de> wrote:> > > Assuming you have a submit button like: > > <submit_tag :id="the_button"> > > > > you could do: > > <select name="region" onChange="document.top_flop_form.the_button.click > ()"> > > > > This should work, though there is probably another way, more railish.. > > This works, thanks! > > > > > Bogdan > > Jonathan > > -- > Jonathan Weiss > http://blog.innerewut.de > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails