Can't cancel keyup event.

F

Frank O'Hara

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top