pawt wrote:
> I thought everyone might like to have this - I didn't like having to
> do a work-around to get the value of the checked radio in a set of
> radio buttons, so I created $FR() - $F for radio buttons =)
It is a failing of Prototype.js that $F() does not return the value of
a radio button set.
[...]
> function $FR(frm, name)
> {
> return $F($(frm).getInputs('radio', name).find(function(obj) { return
> obj.checked; }));
> }
Not too flash: if no buttons are checked, it throws an error. While
it is invalid HTML to have a radio button set without one button
checked, about 99% (complete guess, but not too far wrong I'd reckon)
of pages with radio buttons don't have one checked by default.
Consider the following which uses about the same number of characters,
yet runs 2 to 4 times faster in the browsers I tested (and doesn't
error when none are checked):
function rbValue(el) {
var i = el.length;
while(i--)
if (el[i].checked) return el[i].value;
return el.checked && el.value;
}
Call with something like:
<input onclick="rbValue(this.form.buttonsetName)" ... >
There are many, many libraries out there that do a good job of
returning the value of form elements, including radio buttons.
--
Rob
--~--~---------~--~----~------------~-------~--~----~
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 [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-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---