Hi,

When I run that with Prototype 1.6.0.2, the first alert gives me the
expected result ("2").  If you're seeing different behavior, perhaps
it's related to a version of Prototype, or...?

Two other things I noticed:

1. You're creating global variables ("selects1", "selects2", and
"id").  You probably want to use "var" within the function so they're
local variables.  More on the horror of implicit global variables in
this blog post:
http://blog.niftysnippets.org/2008/03/horror-of-implicit-globals.html

2. Note that "for..in" is for iterating properties of objects, not
elements of arrays, although most of the time you can get away with
thinking that it does elements of arrays.  There are many times when
that will break, though, and one of times (but by no means the only
one) is if you're using Prototype.  More here:
http://www.prototypejs.org/api/array

Hope this helps,
--
T.J. Crowder
tj / crowder software / com

On Apr 28, 2:13 pm, Domini <[EMAIL PROTECTED]> wrote:
> Found some kind of a bug. I think that $$("select") should return at
> least all the elements except $("length") instead of returning an
> empty array.
> #########################
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/
> TR/xhtml11/DTD/xhtml11.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml";>
> <head>
> <meta content="text/html; charset=windows-1251" http-equiv="Content-
> Type" />
> <link href="templates/css/css.inc.css" rel="stylesheet" type="text/
> css" />
> <script src="prototype.js" type="text/javascript"></script>
> <script>
> Event.observe(window,"load",function()
> {
>         selects1=$$("select");
>         alert(selects1.size());
>         // This will give us an empty array! Need a workaround.
>         selects2=document.getElementsByTagName("select");
>         for(id in selects2)
>         {
>                 alert(id);
>         }
>         // This will give us an array with 2 "length" keys.});
>
> </script>
> </head>
>
> <body>
> <form>
> <select name="length" id="length"></select>
> <select name="any" id="any"></select>
> </form>
> </body>
> </html>
> #########################
--~--~---------~--~----~------------~-------~--~----~
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