473,405 Members | 2,415 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,405 software developers and data experts.

assigning event with attachEvent instead of onmouseover

Hello,

I'm having difficulty using attachEvent instead of simply assigning to
mouseover in my object Sample03. When i use myImage.onmouseover =
this.showmouseover(); in the following all works fine, if I replace it by
myImage.attachEvent('onmouseover',this.showmouseov er()); I get for the
alert(this.id) "undefined" and not "gwlogo"

<html>
<head>
</head>
<SCRIPT language="javascript" type="text/javascript">
var Sample03 = function(){
this.Property01 = "Prop01";
var myImage = document.getElementById("gwlogo");
myImage.onmouseover = this.showmouseover();
//myImage.attachEvent('onmouseover',this.showmouseov er());
}
Sample03.prototype.showmouseover = function()
{
var _this = this;
return(
function(e){
alert(this.id);
alert(_this.Property01);
})
}
window.onload=function(){
var mySample = new Sample03();
}

</SCRIPT>
<body>
<img src="http://localhost/winxp.gif" id="gwlogo">
</body>
</html>

Thank you for your assistance.



Jun 27 '08 #1
4 1644
webgour schrieb am 10.06.2008 17:01:
I'm having difficulty using attachEvent instead of simply assigning to
mouseover in my object Sample03. When i use myImage.onmouseover =
this.showmouseover(); in the following all works fine, if I replace it by
myImage.attachEvent('onmouseover',this.showmouseov er()); I get for the
alert(this.id) "undefined" and not "gwlogo"
http://www.quirksmode.org/js/events_advanced.html

"The event handling function is referenced, not copied, so the this
keyword always refers to the window and is completely useless."

--
Mit freundlichen Grüßen
Holger Jeromin
Jun 27 '08 #2
webgour escribió:
I'm having difficulty using attachEvent instead of simply assigning to
mouseover in my object Sample03. When i use myImage.onmouseover =
this.showmouseover(); in the following all works fine, if I replace it by
myImage.attachEvent('onmouseover',this.showmouseov er()); I get for the
alert(this.id) "undefined" and not "gwlogo"
Unless it's just an exercise, I suggest you grab a third-party library
or framework to attach events. Apart from the headaches it'll save, it
won't be IE only. I've often used the code described here (find the
"downloadable version" link):

http://dean.edwards.name/weblog/2005/10/add-event2/
<SCRIPT language="javascript" type="text/javascript">
The language attribute is deprecated.
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--
Jun 27 '08 #3
Holger Jeromin wrote:
webgour schrieb am 10.06.2008 17:01:
>I'm having difficulty using attachEvent instead of simply assigning to
mouseover in my object Sample03. When i use myImage.onmouseover =
this.showmouseover(); in the following all works fine, if I replace it by
myImage.attachEvent('onmouseover',this.showmouseo ver()); I get for the
alert(this.id) "undefined" and not "gwlogo"

http://www.quirksmode.org/js/events_advanced.html

"The event handling function is referenced, not copied, so the this
keyword always refers to the window and is completely useless."
See also:

http://www.quirksmode.org/blog/archi...nt_consid.html
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8*******************@news.demon.co.uk>
Jun 27 '08 #4
On Jun 11, 1:44 am, Holger Jeromin <news03_2...@katur.dewrote:
webgour schrieb am 10.06.2008 17:01:
I'm having difficulty using attachEvent instead of simply assigning to
mouseover in my object Sample03. When i use myImage.onmouseover =
this.showmouseover(); in the following all works fine, if I replace it by
myImage.attachEvent('onmouseover',this.showmouseov er()); I get for the
alert(this.id) "undefined" and not "gwlogo"

http://www.quirksmode.org/js/events_advanced.html

"The event handling function is referenced, not copied, so the this
keyword always refers to the window and is completely useless."
The line above that on Quirksmode is not quite correct, it says (in
regard to the IE event model):

"Events always bubble, no capturing possibility."
When it should say:

"Events *only* bubble..."
Not all events bubble, and some events that bubble in other browsers
do not bubble in IE (such as the change event for form elements).
--
Rob
Jun 27 '08 #5

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

Similar topics

6
by: Fredrik Celin | last post by:
If I add an event (to a div for example) with js, it replaces the event if there already is one. How can I add instead of replace this? Example: <body onLoad="testDiv.onmouseover =...
4
by: Pai | last post by:
hello there, I am trying to rersize the window it works find in IE but doea not work with mozilla window.attachEvent(onload,MWSOnLoad); window.onload = function (MWSOnLoad) { alert('hello');...
7
by: Ron Goral | last post by:
Hello I am new to creating objects in javascript, so please no flames about my coding style. =) I am trying to create an object that will represent a "div" element as a menu. I have written...
5
by: jaysonnward | last post by:
Hello All: I've recently been recreating some 'dropdown menus' for a website I manage. I'm writing all my event handlers into my .js file. I've got the coding to work in Firefox, but the...
4
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...
23
by: Schannah | last post by:
I'm trying to create a design which mimics the Radiohead website in the action on this page, but the problem is that they use PHP for the effect and I have no idea about PHP. I'm very amateur: fairly...
6
by: blaine | last post by:
Hello, I'm currently overriding function keys (F1 to F4) to perform other actions. In order to do this the default popup windows of Help (F1), Seach(F3) etc must be turned off. In FF it's easy...
6
by: TriFuFoos | last post by:
Hi there, I was wondering if anyone knew if/how to assign an event to a global variable? I tried to do it and IE 7 came back with an error saying "Member not found" My code looked similar to...
2
by: markszlazak | last post by:
Could someone check out the following code and please help me understand the problem and fix it. It seems like some events are not firing when my mouse moves over the table cells to quickly causing...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
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.