Ah, good point; I hadn't thought about a radio button set with no
default selected - I included the function in my own project, in which
I'm quite diligent in adhering to things such as having a default
checked. I wholeheartedly agree with your 99% estimate, however =P
Thanks for the correction and the improved function - I appreciate it!
On Apr 27, 9:48 am, RobG <[EMAIL PROTECTED]> wrote:
>
> 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
-~----------~----~----~----~------~----~------~--~---