From: dan_williams on

Thanks RobG, that works a treat.

Dan


RobG wrote:

> If event handlers are coded in the HTML, pass 'event' to the function:
>
> <select onclick="fnSelect(event);">
>
> so now the function looks like:
>
> function fnSelect(e){
> var e = e || window.event;
> e.cancelBubble = true;
> if (e.stopPropagation) e.stopPropagation();
>
> /* rest of function... */
>
> }
>
> Rob

From: Tony on
petermichaux(a)gmail.com wrote:
> dan_williams(a)newcross-nursing.com wrote:
>
>
>>When clicking on my select dropdownlist, does anyone know how i can get
>>my page to only execute the fnSelect function, and not the fnTR
>>function aswell?
>>
>>In my real page, my functions perform other operations (i.e. fnTR
>>highlights the selected row), but i've just put in alerts to
>>demonstrate.
>>
>>Is it possible to do this without having to put onClick events in all
>>my TD elements instead?
>>Is there some sort of void function or return false; i could do? Or is
>>it possible to add some functionality to my fnTR function that would
>>check if I clicked on the dropdown box, and if so, not to perform the
>>rest of the function?
>>
>>Thanks in advance for any suggestions
>
>
> Hi Dan,
>
> It would be nice if there is some thing clean like a return false that
> would stop the tr handler from firing. I don't know if there is.
> Following from your last idea I just tested the following file
>
<snip solution>

Exactly what I did :) It seems to be the best way, but I dislike the use
of a global variable if it can be avoided. I'm not certain this one can
be avoided, though.


--
"The most convoluted explanation that fits all the available and made-up
facts is the most likely to be believed by conspiracy theorists"
From: Tony on
Richard Cornford wrote:
> petermichaux(a)gmail.com wrote:
> <snip>
>
>>It would be nice if there is some thing clean like a
>>return false that would stop the tr handler from firing.
>>I don't know if there is.
>
> <snip>
>
> Understanding how events work in web browsers is fairly fundamental to
> programming a browser as a GUI. It is difficult to see how anyone
> learning to script web browsers could avoid learning this aspect of the
> task within a few months of starting to make the effort

Given that, would you care to offer some sources of information
regarding this sort of scripting?


--
"The most convoluted explanation that fits all the available and made-up
facts is the most likely to be believed by conspiracy theorists"
From: petermichaux on
Richard Cornford wrote:
> petermichaux(a)gmail.com wrote:
> <snip>
> > It would be nice if there is some thing clean like a
> > return false that would stop the tr handler from firing.
> > I don't know if there is.
> <snip>
>
> Understanding how events work in web browsers is fairly fundamental to
> programming a browser as a GUI. It is difficult to see how anyone
> learning to script web browsers could avoid learning this aspect of the
> task within a few months of starting to make the effort (with the
> exceptions of being VK or placing an unreasonable reliance on the
> internal details of a library/framework, the internals of which they did
> not understand).
>
> I hope you will remember the outcome of this thread next time you are
> considering directing people to particular sources of information, or
> recommending particular libraries/frameworks. If you really were
> qualified to judge you would not be expected to be deficient in the
> fundamentals of browser scripting.

Hi Richard,

I only use DOM Level 2 event handling and have never looked at how
stopping event propogation works with the attribute event handlers. I
said it would be nice if there was a way and there is. That's nice. I
learned something by joining in the discussion. I'm pleased to be using
DOM level 2 event handling daily and using it well.

People here have been very unfriendly to those asking about
Prototype.js. They may not have a choice in using it or not. Recently
I've never said much more than "you might have better luck asking on
the rails spinoffs list".

Peter

From: petermichaux on

petermichaux(a)gmail.com wrote:
> dan_williams(a)newcross-nursing.com wrote:
>
> > When clicking on my select dropdownlist, does anyone know how i can get
> > my page to only execute the fnSelect function, and not the fnTR
> > function aswell?
> >
> > In my real page, my functions perform other operations (i.e. fnTR
> > highlights the selected row), but i've just put in alerts to
> > demonstrate.
> >
> > Is it possible to do this without having to put onClick events in all
> > my TD elements instead?
> > Is there some sort of void function or return false; i could do? Or is
> > it possible to add some functionality to my fnTR function that would
> > check if I clicked on the dropdown box, and if so, not to perform the
> > rest of the function?
> >
> > Thanks in advance for any suggestions
>
> Hi Dan,
>
> It would be nice if there is some thing clean like a return false that
> would stop the tr handler from firing. I don't know if there is.
> Following from your last idea I just tested the following file
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
> <html lang="en">
> <head>
> <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
> <title>Test</title>
>
> <script type='text/javascript'>
>
> var flag = false;
>
> function fnTR() {
> if (flag) {
> flag = false;
> } else {
> alert("TR");
> }
> }
>
> function fnSelect() {
> flag = true;
> alert("Select");
> }
>
> </script>
>
> </head>
> <body>
>
> <table width="300" height="50" border="1">
> <tr onclick="fnTR();">
> <td align="center">
> <select onclick="fnSelect();">
> <option>option 1</option>
> <option>option 2</option>
> </select>
> </td>
> </tr>
> </table>
>
> </body>
> </html>
>
> (Note no use of the deprecated language attribute or the <!-- -->
> hiding trick. I don't use "javascript:" and never have. Also I added a
> doctype.)
>
> I'm sure there are many ways to do this but if your situation is
> relatively simple this might be ok.

I should point out that there is one bonus of using a flag to stop the
tr onclick event handler from firing. If you have other listeners
higher up the DOM than tr that you also want to have fire when either
tr or td are clicked, then the flag will just bypass one level in the
bubble up when td is clicked. If you stop the event altogether you
can't do this, as far as I know.

Peter

First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4
Prev: Ping
Next: onmouseleave Firefox equivalent