I''m building a form where I have a set of radio buttons. When any of these are selected I make an AJAX call that needs some values from other fields in the form, but I''m having problems getting those values and maybe someone can help. I have the following code which is essentially repeated for each of the radio buttons: <%= radio_button_tag(:recurrence_period, CalendarRepeatingEvent::RECURRENCE_PERIOD_MONTHLY_BY_DATE, @recurrence_period =CalendarRepeatingEvent::RECURRENCE_PERIOD_MONTHLY_BY_DATE, {:onchange => remote_function(:with => "''recurrence_period=''+this.value +''&recurrence_frequency=#{@recurrence_frequency}&occurrence_number=#{@occurrence_number}''", :url => {:action => ''select_recurrence_period'' })}) %> <label for="recurrence_period">Monthly</label> Note that the 2 values I''m trying to pass back are where I have @recurrence_frequency and @occurrence_number... these are just placeholders because they''re really instance variables passed when the form is initially setup and I just wanted to see if something got passed back. elsewhere in the form are the elements (id=''frequency'' and id=''count'') I want to pull values from and pass back... here''s that code: Every: Frequency: <span id=''frequency''> <%= text_field_tag(:recurrence_frequency, @recurrence_frequency, :size => 2) %> </span> <br/> <br/> How many times? <span id=''count''> <%= text_field_tag(:occurrence_number, @occurrence_number, :size => 4) %> </span> (I hope this code is easy to read as sposted) I tried using the Prototype utility method $F to pull the values (e.g. $F(''frequency'')), but either that doesnt work or I''m doing it wrong. Anybody familiar with this kind of problem? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I''d suggest wrapping everything in a larger container, and then use the handy observe_form helper. <div id="schedule"> ... radio buttons... ... frequency ... ...occurence... </div> <%= observe_form ''schedule'', :url=>your_target_path %> This approach will serialize the input elements of ''schedule'' (the container) any time any one of them changes. You don''t need to add all that messy js script to your checkboxes -- the helper renders one observer that handles it for you. On Mar 11, 7:27 pm, lunaclaire <szager...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''m building a form where I have a set of radio buttons. When any of > these are selected I make an AJAX call that needs some values from > other fields in the form, but I''m having problems getting those values > and maybe someone can help. > > I have the following code which is essentially repeated for each of > the radio buttons: > > <%= radio_button_tag(:recurrence_period, > CalendarRepeatingEvent::RECURRENCE_PERIOD_MONTHLY_BY_DATE, > @recurrence_period => CalendarRepeatingEvent::RECURRENCE_PERIOD_MONTHLY_BY_DATE, {:onchange > => remote_function(:with => "''recurrence_period=''+this.value > +''&recurrence_frequency=#{@recurrence_frequency}&occurrence_number=#{@occurrence_number}''", :url > => {:action => ''select_recurrence_period'' })}) %> > <label for="recurrence_period">Monthly</label> > > Note that the 2 values I''m trying to pass back are where I have > @recurrence_frequency and @occurrence_number... these are just > placeholders because they''re really instance variables passed when the > form is initially setup and I just wanted to see if something got > passed back. > > elsewhere in the form are the elements (id=''frequency'' and id=''count'') > I want to pull values from and pass back... here''s that code: > > Every: > Frequency: > <span id=''frequency''> > <%= text_field_tag(:recurrence_frequency, @recurrence_frequency, :size > => 2) %> > </span> > <br/> > <br/> > How many times? > <span id=''count''> > <%= text_field_tag(:occurrence_number, @occurrence_number, :size => 4) > %> > </span> > > (I hope this code is easy to read as sposted) > > I tried using the Prototype utility method $F to pull the values (e.g. > $F(''frequency'')), but either that doesnt work or I''m doing it wrong. > > Anybody familiar with this kind of problem?--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
lunaclaire
2008-Mar-14 19:58 UTC
Re: remote_function :with parameters from other form fields
Thanks, Andy! I changed the form before I got your answer, but observer_form looks good... thx for the tip. On Mar 12, 8:21 am, AndyV <a...-HmMyXyqgL2CVc3sceRu5cw@public.gmane.org> wrote:> I''d suggest wrapping everything in a larger container, and then use > the handy observe_form helper. > > <div id="schedule"> > ... radio buttons... > ... frequency ... > ...occurence... > </div> > <%= observe_form ''schedule'', :url=>your_target_path %> > > This approach will serialize the input elements of ''schedule'' (the > container) any time any one of them changes. You don''t need to add > all that messy js script to your checkboxes -- the helper renders one > observer that handles it for you. > > On Mar 11, 7:27 pm, lunaclaire <szager...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I''m building a form where I have a set of radio buttons. When any of > > these are selected I make an AJAX call that needs some values from > > other fields in the form, but I''m having problems getting those values > > and maybe someone can help. > > > I have the following code which is essentially repeated for each of > > the radio buttons: > > > <%= radio_button_tag(:recurrence_period, > > CalendarRepeatingEvent::RECURRENCE_PERIOD_MONTHLY_BY_DATE, > > @recurrence_period => > CalendarRepeatingEvent::RECURRENCE_PERIOD_MONTHLY_BY_DATE, {:onchange > > => remote_function(:with => "''recurrence_period=''+this.value > > +''&recurrence_frequency=#{@recurrence_frequency}&occurrence_number=#{@occurrence_number}''", :url > > => {:action => ''select_recurrence_period'' })}) %> > > <label for="recurrence_period">Monthly</label> > > > Note that the 2 values I''m trying to pass back are where I have > > @recurrence_frequency and @occurrence_number... these are just > > placeholders because they''re really instance variables passed when the > > form is initially setup and I just wanted to see if something got > > passed back. > > > elsewhere in the form are the elements (id=''frequency'' and id=''count'') > > I want to pull values from and pass back... here''s that code: > > > Every: > > Frequency: > > <span id=''frequency''> > > <%= text_field_tag(:recurrence_frequency, @recurrence_frequency, :size > > => 2) %> > > </span> > > <br/> > > <br/> > > How many times? > > <span id=''count''> > > <%= text_field_tag(:occurrence_number, @occurrence_number, :size => 4) > > %> > > </span> > > > (I hope this code is easy to read as sposted) > > > I tried using the Prototype utility method $F to pull the values (e.g. > > $F(''frequency'')), but either that doesnt work or I''m doing it wrong. > > > Anybody familiar with this kind of problem?--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---