I have 2 radio boxes in a form. They are in a group (same name) so that only one can be checked.. How can I check and change witch one is checked via JS.. ______________________________________________________________________ Alex Duffield ❖ Principal ❖ InControl Solutions . http:// www.incontrolsolutions.com --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Alex Duffield wrote:> I have 2 radio boxes in a form. They are in a group (same name) so that > only one can be checked.. > > How can I check and change witch one is checked via JS..$F doesn''t use the input''s name, but rather it''s id. Remember, it''s really just a shortcut for $(''foo'').input.value. Right now, $F doesn''t do value assignment, so I''d drop it. Go with something like: if( form.elements[''input_name''].value == ''foo'' ) { form.elements[''input_name''].value = ''bar''; } else { form.elements[''input_name''].value = ''foo''; } -- Michael Peters Developer Plus Three, LP --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I tryed that, and although it would seem to set the value, it would not toggle the actual visual check boxes. I had to give each one an ID and then use $(''radio1'').checked = false; $(''radio2'').checked = true; That works fine for my current situation, but if I have more ______________________________________________________________________ Alex Duffield ❖ Principal ❖ InControl Solutions . http:// www.incontrolsolutions.com On 4-Jun-07, at 1:46 PM, Michael Peters wrote:> > Alex Duffield wrote: >> I have 2 radio boxes in a form. They are in a group (same name) so >> that >> only one can be checked.. >> >> How can I check and change witch one is checked via JS.. > > $F doesn''t use the input''s name, but rather it''s id. Remember, it''s > really just > a shortcut for $(''foo'').input.value. > > Right now, $F doesn''t do value assignment, so I''d drop it. Go with > something like: > > if( form.elements[''input_name''].value == ''foo'' ) { > form.elements[''input_name''].value = ''bar''; > } else { > form.elements[''input_name''].value = ''foo''; > } > > -- > Michael Peters > Developer > Plus Three, LP > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You could use something similar to this: // Sample function to trigger on radio toggle var info = function(data) { $(''debug'').update(data.id + ''-'' + data.value); $(''test'').getInputs(''radio'').each(function(id) { new Form.Element.Observer(id, 0.3, info); }); Where ''test'' is the id of the form containing the radio buttons and ''info'' would be the function to trigger (in the example above, just updates a div with the id of ''debug''). Ian Tyndall> I tryed that, and although it would seem to set the value, it would > not toggle the actual visual check boxes. > > I had to give each one an ID and then use > > $(''radio1'').checked = false; > $(''radio2'').checked = true; > > That works fine for my current situation, but if I have more > > ______________________________________________________________________ > > *Alex Duffield* *❖* *Principal* *❖* *InControl Solutions* *.* > *http://www.incontrolsolutions.com* <http://www.incontrolsolutions.com/> > > > > > On 4-Jun-07, at 1:46 PM, Michael Peters wrote: > >> >> Alex Duffield wrote: >>> I have 2 radio boxes in a form. They are in a group (same name) so that >>> only one can be checked.. >>> >>> How can I check and change witch one is checked via JS.. >> >> $F doesn''t use the input''s name, but rather it''s id. Remember, it''s >> really just >> a shortcut for $(''foo'').input.value. >> >> Right now, $F doesn''t do value assignment, so I''d drop it. Go with >> something like: >> >> if( form.elements[''input_name''].value == ''foo'' ) { >> form.elements[''input_name''].value = ''bar''; >> } else { >> form.elements[''input_name''].value = ''foo''; >> } >> >> -- >> Michael Peters >> Developer >> Plus Three, LP >> >> >> > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---