Click to See Complete Forum and Search --> : OnEvent precedence -- reference?


dfh123
11-22-2003, 12:18 PM
I've tripped on a couple of distinct, but similar, issues recently, and I believe that they might both be related to my lack of understanding of events and precedence. This is to ask if anyone knows of a good reference source that might explain how these things work in more detail than some of the (still helpful) O'Reilly books.

Here are the two examples of things that I don't understand:

1) Have an "onchange" event that calls a validation function for a text field. If user enters data, hits tab, the function is called, and if there's an error, the function (among other things) does a "focus()" call on the original text field, to put the cursor back where the user can fix the error. But the cursor doesn't go there -- it goes to the next field, obviously following the "tab" key that was hit. Change the "onchange" event call to an "onblur" call, and all works fine. So it seems that the "onblur" is invoked somehow "later" than the "onchange", perhaps after the tab key action is actually obeyed, so my function is then successfully overriding it?

2) Text field: desired action is that when a user enters data in the field and hits the "enter" key, it will act as though he hit a button next to the field. That button is one of several "submit" buttons (not the first on the form). I have "onKeyUp" code that tests for a particular character, and then does a "click()" call for the button desired. This code works fine if I test for some arbitrary character; say "a". But if I test for 13 (the value of the enter key) it doesn't catch it. Instead, the form submits as though the first submit button were hit. This acts the same with "onKeyPress". Again, it seems that there is some precedence rule that the system is using to decide that the enter key will be processed before my onKeyUp code.

Sorry this is long-winded; perhaps I'm way off and am just missing something obvious, but I've tried several books, and scanning this forum, and don't see anything that really helps.

Thanks.
-don