Client Side Events That Overlap

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gaz

    #1

    Client Side Events That Overlap

    This is impossible right??

    This is a very simplified description of my form so don't worry if it
    sounds like I could do it a different way, it's just because I have
    simplified it. I have two controls. In control 1 you can update a text
    value, the onblur event of this control will submit the form and
    update the value on the server. When the onclick event of control 2 is
    fired the form is submitted and on return the value in control 1 is
    populated ready for editting.

    You might be able to see the problem. If the onblur of control 1 is
    fired because the user is clicking on control 2 then the event
    handling code wants to submit the form twice. What happens is that the
    onblur event of control 1 is lost because the onclick event of control
    2 overtakes it. So if you make a change to control 1 and expect it to
    be updated when the focus is lost when you click on control 2 then
    you're in for a surprise.

    I think that this is a pretty standard problem in a client-server
    application like this. Only one event that goes back to the server can
    run at a time. Any solutions to get around this are messy and
    unintuitive when looking back at the code.

    To resolve this issue I simply check in the onclick event of control 2
    if a flag has been set by the onblur event of control 1. If it has
    then then I show a warning to the user that they will have to click
    again (not in an alert() box, which makes matters worse!), and I don't
    submit the form because the onblur submit() is running.

    Part of the problem is that when you submit a form the client
    environment still seems to be running for a sub-second, so events can
    get called when they aren't wanted.

    I suppose the point of this message is, has anybody else faced this
    problem and did they hit a brick wall like I have?

    Thanks.
  • kaeli

    #2
    Re: Client Side Events That Overlap

    In article <76ee1253.04051 80341.718cc9f@p osting.google.c om>,
    oopaevah@yahoo. co.uk enlightened us with...[color=blue]
    > This is impossible right??
    >[/color]

    Maybe, maybe not. Depends.
    [color=blue]
    > This is a very simplified description of my form so don't worry if it
    > sounds like I could do it a different way, it's just because I have
    > simplified it. I have two controls. In control 1 you can update a text
    > value, the onblur event of this control will submit the form and
    > update the value on the server. When the onclick event of control 2 is
    > fired the form is submitted and on return the value in control 1 is
    > populated ready for editting.
    >[/color]

    This sounds like the following.
    I edit a field.
    I click on another field.
    The onBlur of F1 fires.
    The onClick of F2 fires.

    If this is the case...

    How this is done is slightly different from IE/Netscape. Is this an
    intranet application? Does everyone use IE, or do you need the Netscape
    code?

    This simple test (see code below) shows that IE6 and Opera fire the blur
    and never even fire the click. Put a value in the first field, then
    click on the second. The alert for blur goes off, but not the click
    alert.
    Netscape 7 fired the click first, then the onBlur.

    So, tell me more about what browsers you need to do this for.

    --- test code ---

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
    "http://www.w3.org/TR/REC-html40/loose.dtd">
    <html>
    <head>
    <title> New Document </title>
    <script type="text/javascript">
    function f_onBlur()
    {
    alert("blur fired");
    }
    function f_onClick()
    {
    alert("click fired");
    }

    </script>
    </head>

    <body>
    <form name="frm1">
    <input type="text" name="t1" onBlur="f_onBlu r();"> <br>
    <input type="text" name="t2" onClick="f_onCl ick();"> <br>
    </form>


    </body>
    </html>

    --
    --
    ~kaeli~
    I can't sleep.
    The clowns might eat me.



    Comment

    • Gaz

      #3
      Re: Client Side Events That Overlap

      > I had to change the code to the following (provide IDs and post to self[color=blue]
      > instead of default.asp) for it to work. When it did, the event fired was
      > always onBlur(). It did let me type while it was processing, but when
      > the new page was returned, the event fired was onBlur(). Are you sure
      > this isn't a problem with your server or browser? I'm using ASP, not
      > ASP.net, and IE6.[/color]

      Your version gave me the same result as my version - I don't
      understand why my version didn't work for you as the changes you made
      shouldn't make much difference I don't think. What version of iis are
      you using? I am using 5.1 with Windows XP. Perhaps you have a faster
      cpu so that the for-loop completes quickly enough so that the client
      doesn't have time to.

      I always get the last event as onClick when I click on control2.

      Comment

      • kaeli

        #4
        Re: Client Side Events That Overlap

        In article <76ee1253.04052 00104.59fd6c0f@ posting.google. com>,
        oopaevah@yahoo. co.uk enlightened us with...[color=blue]
        >
        > Your version gave me the same result as my version - I don't
        > understand why my version didn't work for you as the changes you made
        > shouldn't make much difference I don't think. What version of iis are
        > you using?[/color]

        Honestly, I don't know. It's not my server and I don't have access to
        the administrator. I do know it's running on a real windows server set
        up for high-end applications, so it's a fast, secure machine. I'm also
        on a T3 backbone, so that's fast, too. It's an intranet.
        [color=blue]
        > I am using 5.1 with Windows XP. Perhaps you have a faster
        > cpu so that the for-loop completes quickly enough so that the client
        > doesn't have time to.
        >[/color]

        Well, that could be.
        Let me increase it.
        ....

        Nope, I upped it huge (for n = 0 to 5000000) and no difference. I kept
        clicking and clicking, but still got onBlur.

        This sounds like a bug somewhere. What version of IE are you using? IE5
        had some bugs. I'm using IE6.
        For giggles, get a computer with IE6 on it and test this page out (put
        the page on a server where everyone can get to it), see what happens.

        --
        --
        ~kaeli~
        Jesus saves, Allah protects, and Cthulhu thinks you'd make
        a nice sandwich.



        Comment

        • Lee

          #5
          Re: Client Side Events That Overlap

          Gaz said:[color=blue]
          >
          >the onblur event of this control will submit the form[/color]

          Revisit that decision. In addition to the problem
          that you're having, there are too many things that
          are beyond your control, and the control of the user,
          that can cause a field to lose focus.

          The onBlur event handler should generally only
          be used for tasks that are simple enough to be
          independent of whatever triggered them.

          Comment

          Working...