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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
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
<Domini...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
Hm! I run prototype.js 1.6.0.2 too, but am getting "0" on alert(selects1.size());. What''s your browser? Mine is IE7.0.6001.18000 x64. I know about global variables and for...in. ) Used for...in just to show the difference. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
I think I found another pitfall of IE... IE6 - 0, IE7 - 0, Safari - 2, Firefox - 2. Can anyone try Opera? --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Hi,
I get the same results with IE6 at my end: 0. Opera 9 (Windows) shows
2, as does Safari 3.1.1 (Windows).
Very strange! Another intriguing difference is that if I add this
pair of lines:
] s2 = document.getElementsByTagName("select");
] alert(''Size from gebtn: '' + s2.length);
FF shows what I expected before I thought about it: "Size from gebtn:
2". So does Safari. IE and Opera take the other tack: The select
box with the id "length" replaces the length property -- IE:
"Size
from gebtn: [object]"; Opera: "Size from gebtn:
[HTMLSelectElement]".
I think the lesson here is: Don''t use "length" as an ID. ;-)
--
T.J. Crowder
tj / crowder software / com
On Apr 28, 3:28 pm, Domini
<Domini...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> I think I found another pitfall of IE...
>
> IE6 - 0,
> IE7 - 0,
> Safari - 2,
> Firefox - 2.
>
> Can anyone try Opera?
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---