I have a form that contains address fields for an applicant and a co- applicant. I would like to add a button that allows the user to copy the information from the applicant''s address into the co-applicant''s. Most of the field are text, but there are a couple of select boxes as well. I started out with an array of the names for each, then tried to iterate through them. Here is the code: function copyApplicantAddr() { var appVars ["cAddress2","cCity","cHousingType","cState","cStreetName","cStreetNum","cStreetType","cYearsAtAddr","cZip","cZip4"]; var coappVars ["coAddress2","coCity","coHousingType","coState","coStreetName","coStreetNum","coStreetType","coYearsAtAddr","coZip","coZip4"]; $(coappVars).each(function(e, index){e.value = $ (appVars[index]).value}); } I know my $(appVars[index]) statement is wrong, but I don''t know how to accomplish this through prototype. Anyone have any insight? Thanks! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
If you change your naming convention just slightly, such that the second set of fields uses a predictable prefix/suffix, then you can just use a single array to iterate over. Without looking into how to handle radio buttons, checkboxes, and selects, the code would be something like: $A( ["cAddress2","cCity","cHousingType","cState","cStreetName","cStreetNum","cStreetType","cYearsAtAddr","cZip","cZip4"] ).each( function( controlID ){ $(''co_'' + controlID ).value = $F( controlID ); // this only works for input of type=text and textareas }); The code for the other form element types would involve fetching the element, determining what it is, then using an appropriate method to copy the value over. -justin --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks! that worked like a charm. On Jan 15, 3:22 pm, "Justin Perkins" <justinperk...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> If you change your naming convention just slightly, such that the > second set of fields uses a predictable prefix/suffix, then you can > just use a single array to iterate over. Without looking into how to > handle radio buttons, checkboxes, and selects, the code would be > something like: > > $A( ["cAddress2","cCity","cHousingType","cState","cStreetName","cStreetNum","cStreetType","cYearsAtAddr","cZip","cZip4"] > ).each( function( controlID ){ > $(''co_'' + controlID ).value = $F( controlID ); // this only works > for input of type=text and textareas > > }); > > The code for the otherformelement types would involve fetching the > element, determining what it is, then using an appropriate method tocopythe value over. > > -justin--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---