Connecting Tech Pros Worldwide Forums | Help | Site Map

Can't cancel keyup event.

Frank O'Hara
Guest
 
Posts: n/a
#1: Apr 26 '07
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


Martin Honnen
Guest
 
Posts: n/a
#2: Apr 26 '07

re: Can't cancel keyup event.


Frank O'Hara wrote:
Quote:
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/
Closed Thread