Thursday, June 10, 2010

Onblur, Onclick Event Sequence

This is a highly technical discussion; if you came here for politics, you might want to skip this one.

I've got a JSP where one field (let's call it "agent") calls a Javascript function when the onblur event happens; when you click the Save button in the same JSP, the onclick event calls a different Javascript function. 

The problem is that the function invoked by onblur has to take place before the function invoked by onclick.  If you move the mouse from the agent field to the Save button--and you wait a second or two--the browser correctly identifies that the agent field no longer has focus, the onblur event happens, and then the onclick event happens.  If you TAB or ENTER your way out of the agent field, onblur happens, and hitting the Save button then raises the onclick event.  But if you move the mouse from the agent field to the Save button and click it fairly quickly, onclick event happens before onblur.

Is there some way to prevent onclick from happening until after onblur has taken effect?

1 comment:

  1. Just an idea, haven't tested, but

    <script type="text/javascript">
    function submitForm() {

    function timing() {
    a = 1;
    while (a < 15) {
    if (ready) {
    a = 15
    } else {
    wait (300);
    a = a + 1;

    <input name=agent onfocus="ready=false;" onblur="yadda;ready=true;>

    <input type=button name=submit onclick="timing();">