aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Javascript event handler executes twice Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Javascript event handler executes twice" Watch "Javascript event handler executes twice" New topic
Author

Javascript event handler executes twice

Anoop Krishnan
Ranch Hand

Joined: May 03, 2001
Posts: 163
I have a DIV element in my html page and an image inside the DIV element
as given below


both elements have a onclick event but I want to execute only method "b()" in case the user clicks on the image.Now both a() & b() are executed sequentialy becasue div is the container of the image
do you have any idea how to block execution of a() if the user clicks on the image.
[ August 31, 2005: Message edited by: Anoop Krishnan ]

I just want to know is there any body call my bean's Getter and Setter methods with "Please" in front - My favorite quip from Bugzilla
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39571
    
  27
If you don't want a() to execute, why don't you just remove that onclick handler in the div tag?


Ping & DNS - updated with new look and Ping home screen widget
Anoop Krishnan
Ranch Hand

Joined: May 03, 2001
Posts: 163
Sorry I should have added more details the same div contains a string too so if the user clicks on the string a() must be executed and if the user clicks on the image b() must be executed.
SO I can not leave out the invocation of a()
Anoop Krishnan
Ranch Hand

Joined: May 03, 2001
Posts: 163
Sorry I should have added more details the same div contains a string too so if the user clicks on the string a() must be executed and if the user clicks on the image b() must be executed.
SO I can not leave out the invocation of a()
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39571
    
  27
In that case, why don't you put the string into its own SPAN, and then you can add the event handler to that, instead of putting it into the parent DIV.
Anoop Krishnan
Ranch Hand

Joined: May 03, 2001
Posts: 163
Ok then I have to explain it more
this is the structure


Now I want to allow the user to click anywhere on the entire 200px width
to trigger a() but if he click on the image only b() must be executed
I think this explains more details about the problem
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39571
    
  27
In that case, something like the following should do the trick.
 
wood burning stoves
 
subject: Javascript event handler executes twice
 
Similar Threads
serious problem about script loading
busy/processing icon on the screen, when user takes some action.
Preventing event propagation
Expand / Collapse of div elements
Change Image when Link is Active