whoiskb
11-12-2003, 04:53 PM
I am working on a routine that will cancel the keypress event. I have this working except for when I wire the events up using listeners. I have a simplified example and I don't understand why I can't cancel the event when I use the listener approach.
Any help would be great...
Thanks!
======== CODE ========
<html><body>
With Event Listener: <INPUT type="text" ID="txtNs" NAME="txtNs">
Without event listener: <INPUT type="text" ID="Text1" onkeypress="NSCheck(event);" NAME="txtNs">
<SCRIPT>
var ns = document.getElementById('txtNs');
ns.addEventListener("keypress",NSCheck,true);
function NSCheck(e)
{
// THIS SHOULD CANCEL THE EVENT!!!
e.preventDefault();
}
</SCRIPT>
</body></html>
Any help would be great...
Thanks!
======== CODE ========
<html><body>
With Event Listener: <INPUT type="text" ID="txtNs" NAME="txtNs">
Without event listener: <INPUT type="text" ID="Text1" onkeypress="NSCheck(event);" NAME="txtNs">
<SCRIPT>
var ns = document.getElementById('txtNs');
ns.addEventListener("keypress",NSCheck,true);
function NSCheck(e)
{
// THIS SHOULD CANCEL THE EVENT!!!
e.preventDefault();
}
</SCRIPT>
</body></html>