[Instantrails-developers] RESOLVED - Assistance needed

Bill Walton bill.walton at charter.net
Fri Jun 30 12:24:21 EDT 2006


Hi David,

David Morton wrote:

> I don't see what the bug is.

I'm still doing a bit of research to determine whether or not to call this a 
bug.  I hope you'll understand that this response is not intended to be 
confrontational.  I intend it to be conversational and would be interested 
in your thoughts re: my thoughts below.

> How is a function supposed to work on a particular
> element if there are two elements with the same name?
> If I submit a form with two inputs both named "username"
> I wouldn't expect it to work...

Absolutely.  But...

The DOM is a hierarchy.  The limitation on uniqueness is, as I understand 
it, intended to be at the container level.  If you could point me to a spec 
that says otherwise (i.e., that specifically says that all DOM names have to 
be unique across the DOM), I'll definitely call off my inquiry.  Just coming 
at it from a less-than-completely-informed position, however, I can have two 
forms on the same page, each one having a :name field, without causing any 
problem.  No?  Why would different rules apply to it than to the DOM 
elements inside it?

> In the case of observe_field, I think it is looking
> for a DOM element with the specified name,

I understand that that's what observe_field is doing.  The question I'm 
currently looking at boils down to what it *could* be doing.  A couple of 
things seem to me to be relevant to that question.

First, it seems to me, at this point, that the root of the problem lies in 
the implementation/specification of getElementById("elementID").  In 
Goodman's "Javascript Bible" he says (p.564) "If a document contains more 
than one instance of an ID, the method returns a reference to the first 
element in source code order with that ID."  OK.  But, given the object 
hierarchy, why's it taking such a lame approach to the request.  At a 
minimum, it seems to me we should be able to give getElementById an 
xPath-type name to uniquely identify the element we're asking about.  On a 
slightly different tack, getElementByName returns an array.  Why shouldn't 
getElementById?

Secondly, once we have an element we have access to a whole bunch of 
property information about it that we could use to determine if it's the one 
we're looking for.  In the case of observe_field, it seems odd to me that it 
would throw-up over encountering a <div> with the same name as something 
it's being asked to observe.  AFAIK, a <div> is not something observe_field 
would be observing.  So why couldn't it continue looking for another DOM 
element with that same name that would be an appropriate target?

> Oh, another debugging tip.  Any time you get a
> "undefined method" error, it probably means that the
> object it is trying to do that method on is not what you
> think; so the best bet is to go back to where it is assigned
> and see what the object actually is.

Thanks for the tip.  I'm definitely accruing them in my 'lessons learned' 
bag.  ;-)

Best regards,
Bill 



More information about the Instantrails-developers mailing list