Canceling attached events? 
Author Message
 Canceling attached events?

Is it possible to cancel an attached event?

scenario:
function doIt() {
    button2.attachEvent( "onclick", someCode);

Quote:
}

function someCode() {
alert( 'hey');
Quote:
}

...
<input id="button1" type="button" onclick="doIt();">
<input id="button2" type="button" onclick="event.cancelBubble = true;
event.returnValue = false;">

Clicking on button2 (after button1) displays the alert box.  I understand
why both [event.cancelBubble] and [event.returnValue] don't cancel the event
(the event isn't "bubbled" to someCode... the attached event is defined as a
sibling, not as a parent or child; returnValue only deals with default
action).

Any ideas on how I might "cancel" the onclick event so that any attached
events are not fired?



Fri, 16 May 2003 03:00:00 GMT  
 Canceling attached events?
Jeff,

<script>
doThatCode = true;

function doIt() {
    button2.attachEvent( "onclick", someCode);

Quote:
}

function someCode() {
    if (doThatCode) {
        alert( 'hey');
    }
Quote:
}

</script>

<input id="button1" type="button" onclick="doIt();">
<input id="button2" type="button" onclick="doThatCode=false;">

Should do the trick - not exactly the most elegant solution but it worked in
testing...

Tony.


Quote:
> Is it possible to cancel an attached event?

> scenario:
> function doIt() {
>     button2.attachEvent( "onclick", someCode);
> }
> function someCode() {
> alert( 'hey');
> }
> ...
> <input id="button1" type="button" onclick="doIt();">
> <input id="button2" type="button" onclick="event.cancelBubble = true;
> event.returnValue = false;">

> Clicking on button2 (after button1) displays the alert box.  I understand
> why both [event.cancelBubble] and [event.returnValue] don't cancel the
event
> (the event isn't "bubbled" to someCode... the attached event is defined as
a
> sibling, not as a parent or child; returnValue only deals with default
> action).

> Any ideas on how I might "cancel" the onclick event so that any attached
> events are not fired?



Sat, 17 May 2003 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. attach event to any document with frames ?

2. cannot attach onload event to the window ?

3. Problem with --HTC VBScript to attach event to Element

4. attach/assign event query

5. Attaching with Event Properties Problem

6. Help: Attaching an event to an ActiveX Object

7. Attach events of the external COM-object from WSC component

8. Canceling the right click event

9. Syntax for canceling a form submit in the onSubmit event

10. Canceling InternetExplore event ?

11. onClick event (cancel needs to release db lock on record)

12. OnKeyDown-event: How to cancel the default action of function key's in Internet Explorer

 

 
Powered by phpBB® Forum Software