Re: Get window click unless on a control by XP
XP
Thu May 10 11:56:01 CDT 2007
Hi Mayayana,
Crystal clear now. Thanks so much for taking all the time to respond so
thoroughly! Thanks so much!
"mayayana" wrote:
>
> > <Div ID="lbxSourceFiles">
> > <Select Name=lbxSource...>
> >
> > Now, I don't want the window click to detect a click on this control, so
> how
> > would my Sub look?
> >
>
> You can do the cancel, as posted above, by ThatsIT.net.au.
> That would go something like:
> --------
> Sub lbxSource_onclick()
> window.event.cancelBubble = true
> End Sub
> --------
>
> That would prevent the click from "bubbling up".
> In other words, it stops the event from being "fired"
> at document level.
>
> But you said that you wanted to run your script only
> if the window is clicked and ignore the click if it was
> on any button, listbox, or other control. If you use the
> cancelBubble method then you need to name, and write
> a sub for, all SELECT and INPUTobjects. By using
> the window.event in the document_onclick sub you can
> get the same result with just one sub.
>
> Window.event has a property srcElement, which is basically
> the "tag object" that was clicked. So if you use
> window.event.srcElement then you now have a reference
> to the tag associated with the click and you can access
> any property of that tag. Since all tags have a name
> property in the IE DOM, you can use that if you want to.
>
> window.event.srcElement.tagName returns the HTML
> tag that was clicked: DIV, SPAN, TD, INPUT, BODY, etc.
>
> window.event.srcElement.name will return the tag name,
> if any.
>
> So if you do the following and click on your listbox...
> -------
> Sub Document_OnClick
> msgbox window.event.srcElement.tagName & "-" &
> window.event.srcElement.name
> End Sub
> -------
> ....then you should see a msgbox that says "SELECT-lbxSource".
>
>
> So what I was describing originally was a way to avoid
> needing to deal with cancelling each individual object
> event, since what you really want is a body_onclick sub.
> Since a listbox is a SELECT tag, and a button
> is an INPUT tag, you can respond to any click in the
> window - but not when it's on the listbox or a button -
> by using:
>
> Sub Document_OnClick()
> Dim sTagType
> sTagType = UCase(window.event.srcElement.tagName)
>
> Select Case sTagType
> Case "SELECT", "INPUT" '-- listbox, textbox, button, etc. clicked.
> Exit Sub
> Case else '-- this could be BODY, TD, SPAN, etc.
> msgbox "This is reacting to a click in the window."
> End Select
> End Sub
>
> You could also filter all buttons but not text fields by
> using:
>
> Select Case sTagType
> Case "SELECT"
> Exit Sub
> Case "INPUT"
> '-- drop out clicks on buttons but not on input fields:
> if window.event.srcElement.type = "button" then Exit Sub
> Case else
> msgbox "This is reacting to a click in the window."
> End Select
>
>
>
>