views:

1068

answers:

2

Here's my problem...

I have a text field which uses the javascript onkeyup event to do some "quiet" validation with a tick or cross if the value is valid.

When the enter key is pressed, it does the same validation, but with an alert box advising of any problems. If the enter key is used to clear the alert box, this press of the enter key refires the onkeyup event, which restarts the validation and the alert boxes again.

As soon as I click the OK in the alert box, this naturally stops.

Is there any way I can detect that the enter press was from the alert box?

This definitely happens in opera, safari and firefox.

+1  A: 

Can you ignore the enter key in your onkeyup event handler?

textbox.onkeyup = function( e ) {
    if( e.keyCode == 13 ) {
        return;
    }
    /* your validation here */
}
meouw
This is how I would do it.
Peter Bailey
I'm still wanting to use the enter key to do a full validation with alert boxes. The non enter keys are used to do silent validation
John
+2  A: 

Use the keypress event instead when triggering the behavior of the enter-key.

ozone