[thelist] with Enter, onBlur is preceded by onSubmit

.jeff jeff at members.evolt.org
Fri Jun 14 14:33:01 CDT 2002


bill,

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> From: Bill Haenel
>
> Not to break up the fun, but per chance does anyone have
> an answer to my question? Just in case you don't recall,
> it was "why is IE executing the onBlur event AFTER the
> onSubmit event when the form is submitted with the Enter
> key, and how do I fix it?"
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

the answer to the first part of the question is simple.  the enter key
doesn't cause the cursor to leave the focused field until the browser
changes pages to follow the action attribute of the form.  it's the
unloading of the page that causes the focused element to blur, not the
pressing of the "enter" key.

the answer to the second half isn't so simple.  i would suggest doing what
you can to avoid this ever being an issue.  in general, it's a good practice
to avoid firing field level validation from the onblur event.  you're much
better off using an event like onchange, onkeydown, onkeyup, onkeypress,
etc. -- events that can be cancelled.  these events should be used to either
restrict input or to manipulate the ui, but should be used for validation.
wherever possible, that should be kept within the function that's called
from the onsubmit event handler.

good luck,

.jeff

http://evolt.org/
jeff at members.evolt.org
http://members.evolt.org/jeff/





More information about the thelist mailing list