Follow-up question:

I played around a bit and changed my design.
Now I have some checkboxes (still with ids starting with
"match_this_") and want to check them all with a click on a link.

function selectAllCheckboxes() {
    $$('*[id^="match_this_"]').invoke('writeAttribute', 'checked');
}

This works fine in IE7 but not in FF2.
In FF2, it works when I click it the first time but then, when I
uncheck some checkboxes and click the link again, they don't become
checked again.
I don't get any JS error in the error console or Firebug either.
Does the writeAttribute function have some quirks in FF2?

/z

On Apr 28, 5:41 pm, kangax <[EMAIL PROTECTED]> wrote:
> Thanks, T.J. : )
>
> I'm still in doubt, though, whether "elegant" code is better than
> straightforward one.
> If it wasn't straight-obvious for you what the snippet does, there's a
> big chance it won't be obvious for another developer looking at it (or
> to myself in half a year) :)
>
> - kangax
>
> On Apr 28, 9:36 am, "T.J. Crowder" <[EMAIL PROTECTED]> wrote:
>
> > @kangax -
>
> > > elements.shift().observe('click', function(e) {
> > >   elements.invoke('writeAttribute', 'disabled', e.target.checked);
>
> > That is just so...elegant.  Took me a while to figure it out (missed
> > that part of the OP's question) and *wow* would I comment it, but
> > seriously:  Nice.
> > --
> > T.J. Crowder
> > tj / crowder software / com
>
> > On Apr 28, 12:23 am, kangax <[EMAIL PROTECTED]> wrote:
>
> > > I'll try to be careful this time.
>
> > > 1) Straight-forward way, only checks whether id starts with a string:
> > > var elements = $$('input[type="checkbox"][id^="match_this_"]');
>
> > > 2) A little more precise (based on regexp):
> > > var elements = $$('input[type="checkbox"]').findAll(function(el)
> > > { return /^match_this_\d$/.test(el.id) });
>
> > > Then:
>
> > > elements.shift().observe('click', function(e) {
> > >   elements.invoke('writeAttribute', 'disabled', e.target.checked);
>
> > > })
>
> > > - kangax
>
> > > On Apr 27, 6:40 pm, zoopzoop <[EMAIL PROTECTED]> wrote:
>
> > > > Hi!
>
> > > > I want to (as the topic suggests) get a list/array of all elements on
> > > > a page whose id starts with a string using Prototype.
> > > > For example, I have several checkboxes like this:
>
> > > > <input type="checkbox" id="match_this_1">
> > > > <input type="checkbox" id="match_this_2">
> > > > <input type="checkbox" id="match_this_3">
> > > > <input type="checkbox" id="match_this_4">
>
> > > > I want to find these elements on my page based on the fact that their
> > > > ids start with "match_this".
> > > > Then I want to assign a onclick-function to the first checkbox that
> > > > disables all the other ones.
> > > > Can somebody help me out with how to do this with Prototype?
--~--~---------~--~----~------------~-------~--~----~
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@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to