473,587 Members | 2,543 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with AttachEvent

Hello everyone!
I am trying to copy AttachEvents but i don't know how.
Because innerHTML doesn't copy the AttachEvents.
Here is an example:

<script>
function a(){
alert("is changing");
}
</script>

<div id="d1" name="d1">
<select id="s1" name="s1">
<option>A</option>
<option>B</option>
</select>
</div>

<script>
s1.attachEvent( "onchange", a);
</script>

<div id="d2" name="d2">
</div>

<script>
d2.innerHTML=d1 .innerHTML;
</script>

Can anyone help me?
Jul 20 '05 #1
5 4714
Ivo

"PedroVasconcel os" <pm**@zmail.p t> wrote in message
news:e0******** *************** ***@posting.goo gle.com...
Hello everyone!
I am trying to copy AttachEvents but i don't know how.
Because innerHTML doesn't copy the AttachEvents.
No, because you end up with two elements with id="s1" and that won't work of
course as id's need to be unique. I changed your last line into:

if(s1) alert(s1.tagNam e); // SELECT
d2.innerHTML=d1 .innerHTML;
if(s1) alert(s1.tagNam e); // undefined

HTH
Ivo
Here is an example:
<script>
function a(){
alert("is changing");
}
</script>

<div id="d1" name="d1">
<select id="s1" name="s1">
<option>A</option>
<option>B</option>
</select>
</div>

<script>
s1.attachEvent( "onchange", a);
</script>

<div id="d2" name="d2">
</div>

<script>
d2.innerHTML=d1 .innerHTML;
</script>

Jul 20 '05 #2
Thanks for your reply but that is not the problem as you can see with
this example:

script>
function merda(){
alert("mudou");
}
</script>

<div id="d1" name="d1">
<select id="s1" name="s1">
<option>A</option>
<option>B</option>
</select>
</div>

<div id="d2" name="d2">
</div>

<script>
s1.attachEvent( "onchange",merd a);
</script>

<script>
var i1=d1.innerHTML ;
d1.innerHTML="" ;
d2.innerHTML=i1 ;
alert(s1.tagNam e);

</script>

the innerHTML does not pass the attachEvent. The innerHTML is only a
string and if you look at it, you don't have any reference to the
attachEvent.
So the question remains: How can i copy AttachEvents?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3
"pmsv pmsv" <pm**@zmail.p t> wrote in message
news:40******** *************@n ews.frii.net...
<snip>
So the question remains: How can i copy AttachEvents?


By keeping track of what you attach to which elements and then when you
reproduce one of those elements by any means you repeat the same event
handler attaching operations as have been applied to the original to the
new element.

Richard.
Jul 20 '05 #4
is that the best way? There isn't a way to ckeck the attachEvents
without having to save history??
Thanks

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #5
pmsv pmsv <pm**@zmail.p t> writes:
is that the best way? There isn't a way to ckeck the attachEvents
without having to save history??


No. Unlike the simple "onclick" property, there is no way to get at
the events added with attachEvent (or the non-proprietary
addEventListene r). You must even know them in order to remove them
with detachEvent (or removeEventList ener).

I wouldn't use innerHTML to copy DOM nodes at all, though. I would
rather use the DOM method cloneNode with a true argument to make
it a deep clone.

In your case, you don't even make a copy, you just move the nodes.
You can do that directly:

while(d1.hasChi ldNodes()) {
d2.appendChild( d1.firstChild);
}

This has the advantage of moving the DOM nodes themselves, including
their attached event listeners.

It seems you are writing for IE only (using attachEvent). Otherwise,
you should remember to initialize the variables d1 and d2.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #6

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

Similar topics

1
1118
by: knoak | last post by:
Hi there, I have a php-generated page which can have a variety of layouts, depending on a lot of things. But every layout has the same <head> and <body> so i cannot put an onload in the <body> tag. My problem: I use the following code inside the body, which should be cross-browser: if (window.attachEvent) {
1
2863
by: philjhanna | last post by:
Hi I'm having a problem applying return false to a div via addEventListener. I'm adding this so that I can drag (click-hold-move) over an image. (Its so that I can add zooming to the image) Adding onmousemove="return false" onmousedown="return false" allows this to happen but I want to add events with addEventListener/attachEvent instead. It works in IE6 but not firefox1.0.6
5
14451
by: Bert | last post by:
Hello, I'm having some problems with creating a script that works on both Mozilla browsers as IE. I want to change the background color of textareas and input text fields as soon as somebody has entered something in them. The script below works perfectly in mozilla browsers (netscape 7, firefox 1,...) but doesn't in internet explorer (but it gives no
18
12050
by: luco | last post by:
Hi! I'm having a problem with attachEvent function. I'd like to add attachEvent dynamically to some objects so that each could execute event function with different parameter value. The question is: how to pass the parameter to event function? The following code obviously doesn't work, how should i modify it to get it to work?
5
12568
by: J | last post by:
I am having problems dynamically adding more than one event handler to an input. I have tried the Javascript included at the bottom. The lines inp.attachEvent('onkeyup', makeEventFunc1(strand)); inp.attachEvent('onchange', makeEventFunc2(strand)); individually work in IE, but when used together, only the bottom one remains active. I have also tried
4
1732
by: Andrew Ip | last post by:
Hi everyone, I'm trying to dynamically create an image map for a particular image on my website, and I'm running into an issue where I try to register the "mouseover" and "mouseout" events for the AREAs of my image map. Here is an abbreviated version of my code: ------------------------
2
2445
by: davidson1 | last post by:
Hai friends..for menu to use in my website..i found in one website....pl look below website.... http://www.dynamicdrive.com/dynamicindex1/omnislide/index.htm i downloaded 2 files.... menuitems.js mmenu.js
3
2535
by: rahulgupta | last post by:
i have a textbox and a save_btn which is a hyperlink. when ever enter key is pressed there is a javascript which check if the name in the textbox contains any special characters. but when we press enter it do page postback and does not check for special characters. i have written a javascript function which stops the post back on enter press in textbox. and then i raise the onclick event by document.getElementById(btn_Save).click(). in...
0
7857
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8352
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8222
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6632
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5723
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5396
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3846
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1457
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1194
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.