Similar to a prior response using a CSS selector, but eliminating the
call to #find:

// Returns single value of the checked radio
var value = $F($$('input:checked[type=radio][name=groupName]')[0])

The ":checked" pseudo-class shortcuts to the checked element(s) in the
selector results. However, in a checkbox group, this would suit
better:

// Returns an array of values of checked boxes
var values = $$('input:checked[type=checkbox][name=groupName\
[\]]').pluck('value');

Note the escaped square brackets are how server languages like PHP
generate arrays from multiple checkboxes.

i really wish when dealing with forms, Prototype's functions dealing
with values should address the name instead of the id, since this is
also the attribute that servers deal with to identify values.
Especially when you're forced to use expensive methods like the above
to use a CSS selector, create an array of matches (pointless when you
know there's only one resulting element), and then get its value.

Hope that's useful.
-joe t.


On Apr 30, 1:32 pm, Shane McCarron <halindr...@gmail.com> wrote:
> I am sure this is just ignorance on my part, but...
>
> I would really like to $F('formField') to get the value of whatever field I
> am interested in.  However, it seems formField needs to be the field's ID,
> not its Name.  That's cool, except when I have Radio Buttons or Check
> Boxes.  You aren't allowed to have multiple elements with the same ID and
> still be valid.  What's the right way to do this?
>
> --
> Shane McCarron
> halindr...@gmail.com
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Prototype & script.aculo.us" group.
> To post to this group, send email to prototype-scriptacul...@googlegroups.com.
> To unsubscribe from this group, send email to 
> prototype-scriptaculous+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/prototype-scriptaculous?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.

Reply via email to