Michael Winter wrote: <op**************@news-text.blueyonder.co.uk>
Richard Cornford wrote:> Michael Winter wrote:
>> Mick White wrote:
>>> onclick="comment_text.value=prompt('enter comment')">
^^^^^^^^^^^^>>
>> And if I'm not using IE or Opera?
It will also work with Mozilla/Gecko because of the custom scope
chain added to event handling functions generated from attribute
code. There are still a number of other browsers on which it is
guaranteed to fail because they provide no similar mechanism.
Opera is one of the browsers in which it will fail, despite my
earlier assertion to the contrary.
<snip>
I think you will find that it varies slightly with the version, at least
with Opera 7. Opera <= 6 does not provide any special scope handling
mechanism at all so it only stands a chance of resolving the unqualified
identifier when it is spoofing IE.
One of the main problems with using unqualified identifiers as
references to form controls and forms is that it does work on quite a
lot of browsers (and especially the more modern ones). Either because of
special scope chains created for event handling attribute code or
because the reference is available as a named property of the global
object. But I am yet to see two browsers use the same scope handling
mechanism for attribute code.
A convenient "shortcut" feature that isn't always available and
inconsistently implemented when available is best disregarded for
cross-browser scripting. Better to write attribute code as if it was the
code in a function assigned as an event handler with javascript, without
any sort of special scope chain (and without using element names/IDs as
if they were global properties, even without assuming that the - this -
object is in the scope chain, qualifying identifiers for its properties
also with - this). It is almost certainly only inadequate testing (in an
insufficient range of JS capable browsers) that gives people the
impression that this "shortcut" is viable at all.
Richard.