Rick DeNatale
2007-Oct-04 18:52 UTC
How to update fields when checkbox is selected via javascript without going to server?
I''m having a mental block on this. I''ve got a checkout page form which has ship to and bill to sections. There''s a checkbox which says ''bill to same''. What I''d like to do is fill the bill to fields from the corresponding ship to fields when the checkbox is selected and turned on. I don''t want this to be an AJAX request since I''m just copying things from elements in the DOM. I assume that I want to use observe_field with the :function option, but I''m having a hard time thinking through how to do this. I want to be able to use the prototype helpers to write the function instead of hand coding javascript. Any ideas or example code? -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.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 -~----------~----~----~----~------~----~------~--~---
Tyler MacDonald
2007-Oct-04 18:55 UTC
Re: How to update fields when checkbox is selected via javascript without going to server?
Rick DeNatale <rick.denatale-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I assume that I want to use observe_field with the :function option, > but I''m having a hard time thinking through how to do this. I want to > be able to use the prototype helpers to write the function instead of > hand coding javascript. > > Any ideas or example code?Rick, scriptaculous, included with ruby, would make the javascript for this so simple that you shouldn''t need to bother with protoype helpers, etc. I''d imagine it''d be something like: function copy_fields () { fields = [ "addr1", "addr2", ... ] for(i=0;i<fields.length;i++) { $("ship_" + fields[i]).value = $("bill_" + fields[i]).value } } Cheers, Tyler --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---