I''m using ajax more and more in my apps, and there is one particular piece of technology that I''m missing that would really make things cleaner and smoother. In a normal form, there is a submit button that delivers all of the values of the form objects to the called method. Same is true for an ajax form. Quite often with ajax though, you want to have other buttons or links on the page that change the form in some way, often dependent on the value of one or more form elements. Unfortunately, a regular "LinkToRemote" does not provide any useful form related params to the called method. So far I''ve been dealing with this nuisance by using observers, but that can be slow and probably adds some unnecessary load on the server, and it''s ugly in the code. I''ve discovered that if I include something like :foo => ''bar'' in the url params for a LinkToRemote, then :foo => ''bar'' gets added to the params sent to the called method. What can I put in place of ''bar'' above in the LinkToRemote call that will send the value of a particular form element in the params instead of ''bar''? I''ve tried a few things, but alas, I only played with javascript for a short time before I found out about Rails. When it comes to JavaScript, I am the weakest link. thanks for the help, jp -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jeff Pritchard wrote:> In a normal form, there is a submit button that delivers all of the > values of the form objects to the called method. Same is true for an > ajax form. Quite often with ajax though, you want to have other > buttons or links on the page that change the form in some way, often > dependent on the value of one or more form elements. Unfortunately, a > regular "LinkToRemote" does not provide any useful form related params > to the called method.:with => ''Form.serialize("my_form")'', right? -- Phlip http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Phlip wrote:> Jeff Pritchard wrote: > > :with => ''Form.serialize("my_form")'', right? > > -- > Phlip > http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!What Phlip suggests would send all of the form parameters up as parameters on the AJAX request. If you just want to do one, something like: :with => "\"param_name=\" + $F(''form_elem_name'')" should work well, assuming that form_elem_name is a text field. $F(''x'') in Prototype will give you the value of x if x is a <INPUT type="text"...>. Equally valid should be: :with => "\"param_name=\" + this.form.form_elem_name.value" The thing to realize about the :with parameter is the string it points to needs to be valid, evaluatable (not a word I know :]) Javascript. Hope this makes sense. Wes -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Wes Gamble wrote:> Phlip wrote:> > :with => "\"param_name=\" + this.form.form_elem_name.value" > > > WesThanks Wes and Philip. Wish I had asked this question a few projects ago! jp -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---