Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Overriding an onclick with another onclick

Reply
Thread Tools

Overriding an onclick with another onclick

 
 
tomlong@gmail.com
Guest
Posts: n/a
 
      01-25-2006
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

 
Reply With Quote
 
 
 
 
bobzimuta
Guest
Posts: n/a
 
      01-25-2006
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

 
Reply With Quote
 
 
 
 
BootNic
Guest
Posts: n/a
 
      01-26-2006
> "(E-Mail Removed)" <(E-Mail Removed)> wrote:
> news:(E-Mail Removed) 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*



 
Reply With Quote
 
tomlong@gmail.com
Guest
Posts: n/a
 
      01-26-2006
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/

 
Reply With Quote
 
tomlong@gmail.com
Guest
Posts: n/a
 
      01-26-2006
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Overriding a href using onClick VA Javascript 5 10-31-2005 04:48 PM
button.onclick = new Function("func2()") + button.onclick foldface@yahoo.co.uk Javascript 2 09-26-2005 08:13 AM
Overriding '<a href' with '<a onClick' for JavaScript function openWindow(URL) for image and link... Kevin Lyons Javascript 2 07-27-2004 03:18 PM
overriding client-side onclick of Button =?Utf-8?B?U2VkZWY=?= ASP .Net 2 02-21-2004 07:07 PM
document.onclick=doIt() same as document.onclick=doIt ? bob Javascript 3 08-21-2003 12:14 PM



Advertisments