471,831 Members | 1,204 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,831 software developers and data experts.

Can't cancel keyup event.

I think I'm losing my mind, granted it is kind of late here so...

I'm trying to do some simple validation on the client as keys are
pressed. The validation routine works well enough however I can't
seem to cancel the event should the validation fail. Well more
accurately, I can't cancel the keyup event. When I hook the following
routine to the keydown event it works well and an invalidation cancels
the event. I'm hooking the validation routine to the keyup event
because I need the value of the input with the current key.

function validateDecimalValue()
{
var e = window.event;
var errorMsg = "";
var keyCode = e.keyCode;

if (e.srcElement.value != "" && e.srcElement.value != "-" && !
isValidDecimal(e.srcElement.value,9,2))
{
errorMsg = "INVALID INPUT: Decmial values must lie within the
following range: -9,999,999.99 -9,999,999.99";
}

displayErrorMessage(errorMsg);

if (errorMsg != "")
{
e.returnValue = false;
e.cancelBubble = true;
}

return (errorMsg == "");
}
As I mentioned above, the validation piece works fine I just can't get
it to cancel the event if the validation fails - and I ONLY experience
this behavior (or lack thereof) with the keyup event.

Am I missing something trivial?

Thanks,
Stephan

Apr 26 '07 #1
1 6062
Frank O'Hara wrote:
As I mentioned above, the validation piece works fine I just can't get
it to cancel the event if the validation fails - and I ONLY experience
this behavior (or lack thereof) with the keyup event.

Am I missing something trivial?
Not really, keyup is not cancellable, see
<http://msdn2.microsoft.com/en-us/library/ms536940.aspx>
which says
"Cancels No"

--

Martin Honnen
http://JavaScript.FAQTs.com/
Apr 26 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Gene Hubert | last post: by
2 posts views Thread by Adam J. Schaff | last post: by
11 posts views Thread by Ben | last post: by
NeoPa
reply views Thread by NeoPa | last post: by
aboka
reply views Thread by aboka | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.