On 7 Aug 2004 11:08:58 -0700, Dennis <ml***@yahoo.com> wrote:
[snip]
The difference is in the name attribute. I can name it "displa",
"displays", "displat", or "displa*" and it works. But when I call it
"display" it doesn't work.
Why?
As I'm sure you're aware, most browsers accept the shortcut form/control
accessor that looks like:
document.formName.controlName
In order for this to work, every named form (formName, above) is made a
property of the document object. Likewise, every named form control is
made a property of its parent form.
When the intrinsic event for a form control is executed, the form object
itself is added, for reasons unknown to me, to the scope chain. This scope
chain is used to resolve identifiers. As I already mentioned, named form
controls are added to the form object as properties, so if you use a
control name as an identifier, it will be found in the form. This is why
renaming the form control (or the function) produces the more desired
results: the name you're looking for can't be found in the form object, so
the browser looks to the global object and finds it there[1].
It should be noted that this only occurs when the form control is
contained within a form. If it's by itself, only the control itself, and
the global object, are part of the scope chain[2].
Mike
[1] Apologies for any discrepancies in that description - my knowledge of
the scope chain is a little fuzzy, particularly as to why the form is
added.
[2] Well, that's what I've seen anyway.
--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail