469,306 Members | 1,882 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

Client Side Events That Overlap

Gaz
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.
Jul 23 '05 #1
4 1340
In article <76*************************@posting.google.com> ,
oo******@yahoo.co.uk enlightened us with...
This is impossible right??

Maybe, maybe not. Depends.
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.


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_onBlur();"> <br>
<input type="text" name="t2" onClick="f_onClick();"> <br>
</form>
</body>
</html>

--
--
~kaeli~
I can't sleep.
The clowns might eat me.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #2
Gaz
> I had to change the code to the following (provide IDs and post to self
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.


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.
Jul 23 '05 #3
In article <76**************************@posting.google.com >,
oo******@yahoo.co.uk enlightened us with...

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?
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.
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.


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.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #4
Lee
Gaz said:

the onblur event of this control will submit the form


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.

Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Karl | last post: by
2 posts views Thread by Rick Strahl [MVP] | last post: by
2 posts views Thread by Rea Peleg | last post: by
1 post views Thread by rmgalante | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.