Hi Szymon,

> Try this selector:
>
> $('the-id-of-the-form').select('input[name="rbEncryption"]').each(function(anInput)
> {
>      var listener = yourListener.bind();
>      anInput.observe('eventName', listener);
> });

No need to create a separate function for each radio button, just one
copy is sufficient:

$('the-id-of-the-form').select('input[name="rbEncryption"]').invoke(
    'observe',
    'eventName',
    yourListener.bind(/* ...whatever you're binding to here...*/)
);

or

var listener = yourListener.bind(/* ...whatever you're binding to
here...*/)
$('the-id-of-the-form').select('input[name="rbEncryption"]').each
(function(rb) {
    rb.observe('eventName', listener);
});

FWIW,
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available


On Mar 30, 3:30 pm, Szymon Wilkołazki <wilkola...@gmail.com> wrote:
> simon.murgatroyd wrote:
> > I'm trying to use Form.Element.EventObserver on a set of radio boxes
> > that have the same name like this:
>
> > <input  type="radio"  id="rbEncryption" name="rbEncryption"
> > value="All" >All<br/>
> > <input  type="radio"  id="rbEncryption" name="rbEncryption"
> > value="Yes">Encrypted<br/>
> > <input  type="radio"  id="rbEncryption" name="rbEncryption"
> > value="No">Unencrypted<br/>
>
> As Walter said, you cannot use the same ID attribute on more than one
> element. Only the first element will have the id assigned and all the
> other will have no id attribute assigned (that depends on browser
> though).
>
>
>
> > The problem is it only registers the call back on the first of the
> > radio boxes. If I change the id on each input statement so each uses a
> > differenet name, I can register three callbacks. But I want the radio
> > boxes to operate as a set, with only a single possible value.
>
> > I suspect I am going about this in the wrong way. What is the correct
> > way to do this so that I get told as the user selects a different
> > option?
>
> Try this selector:
>
> $('the-id-of-the-form').select('input[name="rbEncryption"]').each(function(anInput)
> {
>      var listener = yourListener.bind();
>      anInput.observe('eventName', listener);
>
> });
>
> You don't need to use .bindAsEventListener() unless you need to pass
> constant arguments to that listener. Usually that is not the case, and
> simple bind() is sufficient. Its just the method names that are
> misleading.
>
> You can use any css selector in the $$() or .select() functions, so it
> is easiest to use the attribute selector and pass it the name you need
> to find. I think that those funcions support most if not all css3
> selectors.
> If you need, you could be more specific:
> $('the-id-of-the-form).select('input[type="radio"][name="rbEncryption"]'),
>
> but I think there is no need to do that.
>
> --
> Best Regards,
> SWilk
--~--~---------~--~----~------------~-------~--~----~
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-scriptaculous@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