Tagged with 'prototype'
Bug? Prototype, IE, getElementsByClassName, and "length"
I've been swearing like a foul-tempered pirate at IE a lot this week. This was one of the problems, something that seems to be a bug in the popular Prototype framework. Hopefully, my posting it here will save someone else much frustration.
So, I have this form/datagrid thing. I want to have a button that clears the fields (not a reset, which would set them to the default state, I want them blank.) For various reasons, getByClassName seemed the best way to deal with this.
Everything was fine on Moz/Firefox. Safari seems fine. But IE...
Some detective work later, it seems that the problem is caused by *another* field on the page. (With it, problems; without it, no problems.) More detective work suggests that the problem is the field's name ("length").
More precisely, it seems getElementsByClassName in IE (6 and 7, at least) will fail to gather elements (returns zero-length array) if there is an input on the page with 'name="length"'.
Solutions: Change the name of the input, or use the optional parent argument to avoid it.
More: Looking at the getElementsByClassName declaration in prototype.js, I'd guess this is really a problem with $A or getElementsByTagName, but that's as far as I got.