473,402 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Overriding an onclick with another onclick

Hi,

I have a tabular form that each TR has an onclick event to edit the
row. I also have a div in one of the cells on each row that is a delete
button. My problem is that both onclicks are being fired when I click
on the delete div-button, and as a result the item is getting deleted,
then is opened up for editing.

How do I prevent the TR onclick from happening when the delete button
is used?

Thanks!
Tom

Jan 25 '06 #1
4 11416
Without having taken any time to research this, I think you need to
call the cancelBubble function. I think

window.event.cancelBubble = true for the IE event model
and
event.preventDefault() or event.stopPropogation() for mozilla

or try returning false from the event function.

if that doesn't help, trying googling for javascript event propagation

Jan 26 '06 #2
> "to*****@gmail.com" <to*****@gmail.com> wrote:
news:11**********************@g47g2000cwa.googlegr oups.com....

Hi,

I have a tabular form that each TR has an onclick event to edit the
row. I also have a div in one of the cells on each row that is a
delete button. My problem is that both onclicks are being fired
when I click on the delete div-button, and as a result the item is
getting deleted, then is opened up for editing.

How do I prevent the TR onclick from happening when the delete
button is used?


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<script type="text/javascript">
var gt=0;
function nef(x){
if(!gt){
alert('do something')
}
else{
x.parentNode.removeChild(x);
gt=0;
}
}
</script>
<title></title>
</head>
<body>
<table summary="">
<tr onclick="nef(this)">
<td>something 0</td>
<td><button onclick="gt=1">delete</button></td>
</tr>
<tr onclick="nef(this)">
<td>something 1</td>
<td><button onclick="gt=1">delete</button></td>
</tr>
</table>
</body>
</html>

--
BootNic Wednesday, January 25, 2006 11:43 PM

When I was young, I was put in a school for retarded kids for two years before they realized I actually had a hearing loss...and they called ME slow!
*Kathy Buckley*

Jan 26 '06 #3
Actually using the cancelBubble was much easier than what you
suggested, even though your way would have worked as well.

Here's a snippet of how it works:

<tr onclick="doSomething();">
<td>Tron 2.0</td>
<td>
<div onclick="window.cancelBubble=true;deleteItem();">
<img src="trashIcon.gif" />
</div>
</td>
</tr>

So pretty simple really. Based on these documents, it looks like it
hits MSIE/Moz:

http://www.mozilla.org/docs/dom/domr...vent_ref4.html
http://msdn.microsoft.com/workshop/a...ncelbubble.asp

Thanks!
Tom Longson (nym)
http://igargoyle.com/

Jan 26 '06 #4
Whoops, it's actually event.cancelBubble, not window.cancelBubble.

A good tutorial on this subject can be found here:
http://www.huntingground.freeserve.c...ncelbubble.htm

Jan 26 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Mike Gratee | last post by:
Is it possible to use JavaScript to cause the browser to click a link on a page and have the browser act exactly like the user had clicked on the link directly? In other words, I need to...
3
by: Jamie Jackson | last post by:
I'm rewriting all links' onclick events, but I'm having a problem. The onclick event that I'm inserting works correctly in Opera, but not in FF or IE. I'm retroactively adding the statement...
2
by: Sedef | last post by:
Hi, i'm trying to create a custom Button user control which will be derived from System.Web.UI.WebControls.Button. the normal server side Button class creates some client side javascript code for...
7
by: extremerep | last post by:
My task is to change the value of a button and then make it functional with the onClick handler. Changing the value to "Play Again" works, but making the onClick work accordingly does not. The...
8
by: Geoff Cox | last post by:
Hello, When using Internet Explorer, on networked PCs in a college, to view a page of mine with Javascript code in it the "stack overflow" error message appears. When I access the same file...
11
by: Daz | last post by:
Hello everyone. I am sure the answer to my question is simple, but I can't seem to dynamically add an onClick event to my script. I have a table which is generated dynamically, I am just...
6
by: Steve | last post by:
I want to disable the onclick for a <div>. In onclick I am using Spry.Effect.AppearFade(...). Any suggestions on how to disable onclick after the first initial click from the user?
18
by: wizdom | last post by:
Help - change text on click - text has another onclick inside with php variables ---------- I think what I'm trying to do is simple. I have a 2 buttons on a page. 1 button allows a thread of...
11
sueb
by: sueb | last post by:
I have a file that I would like to copy from a static location to one based on the value in a control (ChartNum) when the user clicks a button I'll provide for this purpose. I know how to create...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.