473,749 Members | 2,451 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using window.event

I have a set of HTML elements that I add an onclick event to at
runtime. All it does is get the contents of an element using
innerHTML.

It all works fine in Firefox, but I can't get it to work in IE. No
doubt I have a really simple error.... help!

window.event returns an object, but
window.event.to Element returns null.

A broken (in IE) sample snippet is below:

<html><head><ti tle>Arrgghhh</title>
<script type="text/javascript">
ie = document.all;
function showTxt(e) {
var d = (ie) ? window.event.to Element.innerHT ML :
e.target.innerH TML;
alert(d);
}
function addClick(){
document.getEle mentById('rob') .onclick = showTxt;
}

</script>
</head>
<body onload="addClic k();">
<p id="rob">here is robs text</p>
</body>
</html>
Jul 23 '05 #1
2 6099
On Wed, 10 Nov 2004 05:58:04 GMT, RobG <rg***@iinet.ne t.auau> wrote:

[snip]
window.event returns an object, but
window.event.to Element returns null.
It should. The toElement property, and its partner fromElement, are used
with the mouseout/over events to indicate where the mouse is going
to/coming from. The source of the event is given by srcElement.
<script type="text/javascript">
ie = document.all;
Umm...
function showTxt(e) {
var d = (ie) ? window.event.to Element.innerHT ML :
e.target.innerH TML;


That isn't actually necessary.

var d = this.innerHTML;

should do. If you were to use the event object, the proper way would be
something like:

var d = (e ? e.target : window.event.sr cElement).inner HTML;

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2
Michael Winter wrote:
[...]

That isn't actually necessary.

var d = this.innerHTML;

should do. If you were to use the event object, the proper way would be
something like:

var d = (e ? e.target : window.event.sr cElement).inner HTML;


Thanks Michael, your first hint did the trick. I also appreciate your
abbreviated MS DOM test. I'd seen a similar version which would be (in
this case):

var d = (window.event ? window.event.sr cElement:e.targ et).innerHTML;

But I think yours is better as it is more precise - it tests exactly
what I'm about to use - but I expect the result would be about as
consistent.

Rob.
Jul 23 '05 #3

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

Similar topics

5
20778
by: Jeff Thies | last post by:
I have this IE specific bit of code for finding the originating node: var obj=window.event.srcElement; How do I do that cross browser (Opera, NS, Safari...)? Is there a standard DOM method? I seem to recall NS worked something like this: onmousedown=handleThat;
3
27192
by: Søren M. Olesen | last post by:
Hi In IE there seem to be a global variable window.event, holding the current event....however this dowsn't work in FireFox... is there a similar way to get the current event?? TIA Søren
1
20772
by: Perttu Pulkkinen | last post by:
I have different functions that receive window.event as parameter. Functions are used like this: <input type="text" id="x" onkeypress="return onKeyCurrencyCheck(ev, 'x')" onblur ="onBlurCurrencyCheck(event, 'x')""> Works very well with IE, but window.event and maybe window.event.keycode too seems to be missing form firefox. Is there a workaround for this?
5
5212
by: chad.a.morris | last post by:
Hi everyone, I didn't know how to sum this up very well for the title, but hopefully the person(s) will come along who can help. I'm trying to use the window.event.clientX value for positioning a javascript routine, but I'm having trouble. When the javascript routine comes up, it comes up in a certain position based on window.event.clientX. However, the user could click on something in the script display (say, like a menu, or a...
9
6840
by: mike | last post by:
I have this script executing <script> function mike_test(event) { x = window.event.clientX; alert(x); } </script> <iframe src="blank.html" id="my_iframe1"> </iframe>
1
2533
by: den2005 | last post by:
Hi everybody, I am new in javascript. I am working on resizing a control like Image by dragging it to a desired size at runtime. Now, my onmouseover event is working ok where the cursor type is change when position on particular part of control. But the function being called by my onmousedown event has error telling me a syntax error on line 90 (mouseDragImage). What is wrong with it? Thanks in advance. den2005 function...
6
1826
by: Murray Hopkins | last post by:
Hi. THE QUESTION: How do I get a reference to my Object when processing an event handler bound to an html element ? CONTEXT: Sorry if it is a bit long. I am developing a JS calendar tool. One of the requirements is that the calendar will need to display a varying number of months (1..3)
5
6486
by: anEchteTrilingue | last post by:
Hi everybody. Thank you for reading my post. I am having trouble getting "this" to work in all versions of IE (it's fine in Firefox, opera, konqueror, etc). What I would like to do is add an event listener to an element to change its border on mouseover and mouseout. I don't want to use CSS to do this (long story). The problem is that "this" does not work at all in IE for me. I tried to do a try/catch statement and use...
5
1812
by: sdt76 | last post by:
Hi everybody! I have a question regarding IE. I have a client using a script (which I can not change as it is an affiliate program's script that I can not control) that creates a variable called "event" and assigns a number to it. This is the line: var event=7348734; Later on, there is another script that should use window.event, but... it does not work, because window.event gets rewritten by the previous script and it stays filled by...
0
8833
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
9389
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
9256
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
8257
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
6801
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
4709
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
3320
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2794
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2218
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.