On Jul 20, 2011, at 1:07 AM, Bob Smith wrote:

I have a partial called people that has a radio button called hoh for
head of household. I'm trying to have JavaScript look at each person
and find the one that has hoh=1. This record then has it's name copied
to another field used for mailings. The web page has each record from
the partial with a different id, household_person_1001,
household_person_1030, etc. I can't see a way to get all the person
records into a JavaScript array. Please help.



Parts of this seem pretty easy, but there's one thing you didn't mention -- where are the names stored? Are these radio buttons set up with value="Bob Smith" or are they value="1030" (the ID)?

If you apply a classname to these radio buttons, then it's easy to grab all of them.

var hoh_chosen = $$('input.hoh:checked');

Now you have all of the checked radio buttons with class="hoh" applied to them. You iterate over them and find the nearby associated mailing field:

hoh_chosen.each(function(elm){
  // here I'm making another guess about your layout, that
  // you've added a div around the common inputs for each person, and
  // you've applied the classname mailing_name to that text field
  var mailing = elm.up('div').down('input.mailing_name');
  if(mailing){
    mailing.setValue(elm.getValue());
    // and that only works if the value of the radio is what you want
  }
});

So lots of assumptions here, but it's really quite terse to do with Prototype if the value is there to steal. But if your radio buttons only have the ID, then I wouldn't set the mailing name here, but in the controller after the form is submitted. There, you can look up the user by the ID chosen in your hoh radio, and it's all there for you.

Walter

Bob <[email protected]>

--
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- [email protected]. To unsubscribe from this group, send email to [email protected] . For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en .


--
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to