473,322 Members | 1,736 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,322 software developers and data experts.

can't cancel event in IE

What I am attempting to do is cancel an event in IE inside of my event
handler, but the handler keeps getting called:
for example if I do
<div id="foo">
<div id="test">test text</div>
</div>

and assign an event by doing:
document.attachEvent("onclick",functionName)

IE seems to be firing the event twice. Is there a way to stop it?

the function looks like:

function functionName(e){
if (!e) e = window.event; // IE event model
//do something then:

if (e.stopPropagation) e.stopPropagation(); // DOM Level 2
else e.cancelBubble = true; // IE
}

// Now prevent any default action.
if (event.preventDefault) event.preventDefault(); // DOM Level
2
else event.returnValue = false;

}

Apr 3 '06 #1
1 2966
dave wrote:
What I am attempting to do is cancel an event in IE inside of my event
handler, but the handler keeps getting called:
for example if I do
<div id="foo">
<div id="test">test text</div>
</div>

and assign an event by doing:
document.attachEvent("onclick",functionName)

IE seems to be firing the event twice. [...]


Your code looks OK to me (although your feature test could be better).
Could it be that you call document.attachEvent() twice? Also note that
`document' does not refer to an element object.
PointedEars
Apr 4 '06 #2

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

Similar topics

2
by: Donna Sabol | last post by:
Maybe it's not me. I posted a question earlier about not getting a function call right. Well, now I'm trying to write some very simple code, and I can't get ANYTHING to work. It won't even...
7
by: MLH | last post by:
I tried the following code to prevent a checkbox from being updated (going from a value of Null to True, from True to False or from False to True). I was surprised it did not work. Can anyone...
1
by: AP | last post by:
Hi, I'm trying to use c# to pop up a dialog box when a user attempts to close word to prompt them if they want to exit or cancel (obviously other stuff needs to happen based on their selection...
0
by: Rachel Suddeth | last post by:
I have a tabbed ap, and I want to provide a message and give the user a chance to change there mind if they try to change tab pages in the middle of an update (otherwise just cancel the update and...
2
by: Bob | last post by:
In a winform with a datagridview using cellvalidating event but also have a save button that is located on a tablebindignnavigator. The behaviour I observe is that if the cellvalidating issues a...
21
by: Darin | last post by:
I have a form w/ a textbox and Cancel button on it. I have a routine to handle textbox.validating, and I have the form setup so the Cancel button is the Cancel button. WHen the user clicks on...
4
by: Academic | last post by:
Does it make sense to put this If e.Cancel Then Exit Sub at the beginning of form closing events so if the user cancels the app's exiting in one Closing routine he will not be asked again by...
10
by: Benton | last post by:
Hi there, I have a UserControl with a couple of textboxes and a couple of buttons ("Save" and "Cancel"). The Click event for this buttons is in the UserControl's codebehind of course, so here's...
1
by: Frank O'Hara | last post by:
I think I'm losing my mind, granted it is kind of late here so... I'm trying to do some simple validation on the client as keys are pressed. The validation routine works well enough however I...
2
by: =?Utf-8?B?UmljaA==?= | last post by:
Is there a cancel argument for cancelling if you want to check or uncheck a checkbox? In the checkChanged event of a checkbox I ask the user if they are sure they want to check/uncheck...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.