donpro wrote:
I have the following function that check for the <Enterkey being
pressed on an <Inputfield:
function disableCR(e) {
if (window.event) {
key = window.event.keyCode;
} else {
key = e.which;
}
[...]
}
My previous HTML was like so:
<input type="text" name="total" value="100" size="6" maxlength="4"
`type="text"' is redundant as that is the default value for that attribute.
onkeypress="return disableCR(event)">
I would like to convert this into an Event Listener using DOM but not
sure how to do this. Has anyone done this?
You are already using a event listener, and you are using the DOM; in fact,
you are supporting at least three DOMs: the MSHTML-DOM with window.event,
the W3C-DOM and the NN4/Gecko-DOM with `e', and the NN4/Gecko-DOM with
`e.which'.
The local `event' property in the execution context of the event listener
code is proprietary to refer to an Event object, indeed, but I have yet to
see a DOM that does not have it. Avoiding it will only lead to your
scripting branches for several DOM Event implementations, of which only
three are known.
IOW: If it ain't broken, don't fix it.
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann