469,349 Members | 1,501 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,349 developers. It's quick & easy.

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 5976
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
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.