In this code: <html> <head> <title>PT test</title> <script type=''text/javascript'' src=''/js/prototype/1.6.0/ prototype.js''></script> <script type=''text/javascript''> //<![CDATA[ Event.observe(window, ''load'', function () { alert($(''login_username'')); }); //]]> </script> </script> </head> <body> <input type=''text'' name=''login_username'' id=''login_username_index'' /> </body> </html> IE6 alerts "[object]". IE7 alerts "[object]". Opera 9 alerts "[object HTMLInputElement]". FF2 alerts "null". If I change the name of the input element from "login_username" to anything else, all browsers alert "null". Why is the dollar function reading the name attribute instead of the id? The way I''ve always understood it, the dollar function ignores the name attribute. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Dec 6, 2007 11:12 AM, Matt Alexander <mattalexxpub-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> In this code: > [SNIP] > <input type=''text'' name=''login_username'' id=''login_username_index'' /> > [SNIP] > If I change the name of the input element from "login_username" to > anything else, all browsers alert "null". Why is the dollar function > reading the name attribute instead of the id? The way I''ve always > understood it, the dollar function ignores the name attribute.Well, the id of that input is actually "login_username_index" so unless there''s another element with an id of "login_username", $ is going to be unable to find any matching elements, and thus returns null. :Dan Dorman --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Dec 6, 11:27 am, "Dan Dorman" <dan.dor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Well, the id of that input is actually "login_username_index" so > unless there''s another element with an id of "login_username", $ is > going to be unable to find any matching elements, and thus returns > null. > > :Dan DormanYes, in Firefox. The results of my tests reflect that Prototype 1.6.0 is reading the name attribute in some other browsers. If you run my test and find something different, I''d love to hear about it. == TEST 1 ======================== <input type=''text'' name=''login_username'' /> IE6 alerts "[object]". IE7 alerts "[object]". Opera 9 alerts "[object HTMLInputElement]". FF2 alerts "null". == TEST 2 ======================== <input type=''text'' name=''blablabla'' /> IE6 alerts "null". IE7 alerts "null". Opera 9 alerts "null". FF2 alerts "null". --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
It''s not a Prototype issue. document.getElementById in Opera and IE (incorrectly) returns elements "identified" by the name. Matt Alexander escreveu:> On Dec 6, 11:27 am, "Dan Dorman" <dan.dor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Well, the id of that input is actually "login_username_index" so > > unless there''s another element with an id of "login_username", $ is > > going to be unable to find any matching elements, and thus returns > > null. > > > > :Dan Dorman > > Yes, in Firefox. The results of my tests reflect that Prototype 1.6.0 > is reading the name attribute in some other browsers. If you run my > test and find something different, I''d love to hear about it. > > == TEST 1 ========================> > <input type=''text'' name=''login_username'' /> > > IE6 alerts "[object]". > IE7 alerts "[object]". > Opera 9 alerts "[object HTMLInputElement]". > FF2 alerts "null". > > == TEST 2 ========================> > <input type=''text'' name=''blablabla'' /> > > IE6 alerts "null". > IE7 alerts "null". > Opera 9 alerts "null". > FF2 alerts "null".--~--~---------~--~----~------------~-------~--~----~ 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 wonder if there are plans with the Prototype guys to take this loose functionality out of the dollar function. Leave it in document.getElementById where it belongs. On Dec 6, 12:09 pm, Fabio <fabiow...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> It''s not a Prototype issue. > document.getElementById in Opera and IE (incorrectly) returns elements > "identified" by the name. > > Matt Alexander escreveu: > > > On Dec 6, 11:27 am, "Dan Dorman" <dan.dor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Well, the id of that input is actually "login_username_index" so > > > unless there''s another element with an id of "login_username", $ is > > > going to be unable to find any matching elements, and thus returns > > > null. > > > > :Dan Dorman > > > Yes, in Firefox. The results of my tests reflect that Prototype 1.6.0 > > is reading the name attribute in some other browsers. If you run my > > test and find something different, I''d love to hear about it. > > > == TEST 1 ========================> > > <input type=''text'' name=''login_username'' /> > > > IE6 alerts "[object]". > > IE7 alerts "[object]". > > Opera 9 alerts "[object HTMLInputElement]". > > FF2 alerts "null". > > > == TEST 2 ========================> > > <input type=''text'' name=''blablabla'' /> > > > IE6 alerts "null". > > IE7 alerts "null". > > Opera 9 alerts "null". > > FF2 alerts "null".--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Matt, What "loose" functionality are you talking about ? Best, Tobie On Dec 6, 9:21 pm, Matt Alexander <mattalexx...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I wonder if there are plans with the Prototype guys to take this loose > functionality out of the dollar function. Leave it in > document.getElementById where it belongs. > > On Dec 6, 12:09 pm, Fabio <fabiow...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> It''s not a Prototype issue. > > document.getElementById in Opera and IE (incorrectly) returns elements > > "identified" by the name. > > > Matt Alexander escreveu: > > > > On Dec 6, 11:27 am, "Dan Dorman" <dan.dor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Well, the id of that input is actually "login_username_index" so > > > > unless there''s another element with an id of "login_username", $ is > > > > going to be unable to find any matching elements, and thus returns > > > > null. > > > > > :Dan Dorman > > > > Yes, in Firefox. The results of my tests reflect that Prototype 1.6.0 > > > is reading the name attribute in some other browsers. If you run my > > > test and find something different, I''d love to hear about it. > > > > == TEST 1 ========================> > > > <input type=''text'' name=''login_username'' /> > > > > IE6 alerts "[object]". > > > IE7 alerts "[object]". > > > Opera 9 alerts "[object HTMLInputElement]". > > > FF2 alerts "null". > > > > == TEST 2 ========================> > > > <input type=''text'' name=''blablabla'' /> > > > > IE6 alerts "null". > > > IE7 alerts "null". > > > Opera 9 alerts "null". > > > FF2 alerts "null".--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Dec 6, 2007 1:21 PM, Matt Alexander <mattalexxpub-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I wonder if there are plans with the Prototype guys to take this loose > functionality out of the dollar function. Leave it in > document.getElementById where it belongs.Why? Any potential problems come from sloppy coding. If all the needed ids are in the proper place, everything''s fine. If a developer is _relying_ upon the funky name-based behavior, then the onus is on the developer to deal with the issues raised by coding in a non-standard way. :Dan Dorman --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Tobie Langel wrote:> Matt, > > What "loose" functionality are you talking about ? > > Best, > > Tobiedocument.getElementById should totally ignore the name attribute. That''s loose functionality in JavaScript. On Dec 6, 1:46 pm, "Dan Dorman" <dan.dor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Why? Any potential problems come from sloppy coding. If all the needed > ids are in the proper place, everything''s fine. If a developer is > _relying_ upon the funky name-based behavior, then the onus is on the > developer to deal with the issues raised by coding in a non-standard > way. > > :Dan DormanI had to tweak my standard, not-sloppy code in order to sidestep this sloppy JavaScript functionality: I was trying to detect whether a certain element exists on the page: <script> if ($(''login_username'')) { // ... } </script> The input that had the ID of "login_username" did *not* exist on the page so the ifthen should have evaluated false. It didn''t though, because there was another input on the page with a "name" attribute set to "login_username". This is an example of a problem arising from loose JavaScript functionality. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Dec 6, 2007 3:00 PM, Matt Alexander <mattalexxpub-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> document.getElementById should totally ignore the name attribute. > That''s loose functionality in JavaScript. > > The input that had the ID of "login_username" did *not* exist on the > page so the ifthen should have evaluated false. It didn''t though, > because there was another input on the page with a "name" attribute > set to "login_username". This is an example of a problem arising from > loose JavaScript functionality.As Fabio mentioned, it''s not really a Prototype problem, it''s a problem with how the browser vendors implemented the document.getElementById method. You can make the argument that Prototype is there to clean up these sorts of cross-browser issues, since Prototype does just that very well in so many areas. That''s valid, but the question is if it''s worth taking a performance hit to one of Prototype''s core functions to satisfy an edge case that can be easily remedied. After all, there will probably always be cross-browser issues in Web development. And I''m sorry if you thought the "sloppy coding" comment was directed at you, Matt, ''cause it wasn''t--I was just trying to make a general statement. Obviously, that wasn''t clear enough, and I apologize: no slight was intended. :Dan Dorman --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
No problem. :-) On Dec 6, 4:15 pm, "Dan Dorman" <dan.dor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Dec 6, 2007 3:00 PM, Matt Alexander <mattalexx...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > And I''m sorry if you thought the "sloppy coding" comment was directed > at you, Matt, ''cause it wasn''t--I was just trying to make a general > statement. Obviously, that wasn''t clear enough, and I apologize: no > slight was intended. > > :Dan Dorman--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Just a quick, non-standard hack for your problem, you could try: if( $(''login_username'') && $(''login_username'').id==''login_username'') Much faster than debugging wrongities.. :D But Matt, this is really valuable information. I do my best to always couple each form control with ... <input name="same_as_id" id="same_as_id" val... but never actually figured out why... now I know.. Cheers to cross browser issues!! On Dec 7, 12:19 am, Matt Alexander <mattalexx...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> No problem. :-) > > On Dec 6, 4:15 pm, "Dan Dorman" <dan.dor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On Dec 6, 2007 3:00 PM, Matt Alexander <mattalexx...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > And I''m sorry if you thought the "sloppy coding" comment was directed > > at you, Matt, ''cause it wasn''t--I was just trying to make a general > > statement. Obviously, that wasn''t clear enough, and I apologize: no > > slight was intended. > > > :Dan Dorman--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Dec 6, 2007 12:09 PM, Fabio <fabiowgus-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > It''s not a Prototype issue. > document.getElementById in Opera and IE (incorrectly) returns elements > "identified" by the name.Naturally, since I was so vehement that this issue could be so easily worked around, I got bitten by a variant of the same problem when I whipped up some sample code to fool around with Ajax.Updater. The problem occurred when I was trying to load some scripts with Ajax.Updater (thus evalScripts is set to true). If I declared a function in the script being loaded, and gave that function a name which matched any DOM element''s id, then I got an error in IE (Firefox and Opera handled the situation without complaint). Some code demonstrating the issue: // index.html (simplified to show the relevant stuff) <script> document.observe(''dom:loaded'', function() { new Ajax.Updater(''foo'', ''ajax.html'' { evalScripts: true, onComplete: function() { $(''whee'').observe(''click'', function() { whee(); }); } }); }); </script> <div id="foo"></div> // ajax.html <input id="whee" value="whee" /> <script> whee = function() { alert(''whee''); } </script> However, if the conflictingly named function is declared in the same script, IE can handle it without a problem. Obviously, this is a somewhat contrived example with an easy workaround (or two), but I thought it was funny and apropos that I ran into the same problem I claimed was a no-brainer to avoid. Nevertheless, it shows the issues with IE and DOM naming conflicts run a bit deeper than just getElementById. :Dan Dorman --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---