473,655 Members | 3,105 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting event information in IE.

I am dynamically adding rows to a table, and each row have a button which
removes it.
I have successfully implemented this for mozilla but I'm having troubles
with IE, here is how I did it:

Each new row's id is an index number, each button's name is the row's id,
and I'm adding this function as the click event listener for the button:

function removeline(even t){
var row=document.ge tElementById("r ow" + event.target.na me);
var tbody=document. getElementById( "items");
var olds=tbody.styl e.display;
tbody.style.dis play="none";
tbody.removeChi ld(row);
tbody.style.dis play=olds;
}

I'm adding it this way:

var newbutton=docum ent.createEleme nt("INPUT");
newbutton.type= "button";
newbutton.value ="Remove";
newbutton.id=ro wcount;
newbutton.name= rowcount;
if(navigator.us erAgent.match(" MSIE")) // for IE compatibility
newbutton.attac hEvent("onclick ",removelin e);
else
newbutton.addEv entListener("cl ick",removeline ,false);
But IE doesn't pass nothing as a parameter for removeline().
Any suggestions?

Thanks,
-Amir.
--
Remove the 'dont_spam_me' and the dashes before mailing me.
Jul 20 '05 #1
6 2325
On Thu, 26 Feb 2004 18:58:22 +0200, Amir Hardon
<ha************ ******@actcom.c o.il> wrote:
I am dynamically adding rows to a table, and each row have a button which
removes it.
I have successfully implemented this for mozilla but I'm having troubles
with IE, here is how I did it:

Each new row's id is an index number, each button's name is the row's id,
and I'm adding this function as the click event listener for the button:

function removeline(even t){
var row=document.ge tElementById("r ow"
+ event.target.na me);
var tbody=document. getElementById( "items");
var olds=tbody.styl e.display;
tbody.style.dis play="none";
tbody.removeChi ld(row);
tbody.style.dis play=olds;
}

I'm adding it this way:

var newbutton=docum ent.createEleme nt("INPUT");
newbutton.type= "button";
newbutton.value ="Remove";
newbutton.id=ro wcount;
newbutton.name= rowcount;
if(navigator.us erAgent.match(" MSIE")) // for IE compatibility
newbutton.attac hEvent("onclick ",removelin e);
else
newbutton.addEv entListener("cl ick",removeline ,false);
But IE doesn't pass nothing as a parameter for removeline().
Any suggestions?

Thanks,
-Amir.


--
Michael Winter
M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #2
[Apologies if another post is received - it should have been cancelled]

On Thu, 26 Feb 2004 18:58:22 +0200, Amir Hardon
<ha************ ******@actcom.c o.il> wrote:
I am dynamically adding rows to a table, and each row have a button which
removes it.
I have successfully implemented this for mozilla but I'm having troubles
with IE, here is how I did it:

Each new row's id is an index number, each button's name is the row's id,
and I'm adding this function as the click event listener for the button:
[snip]
if(navigator.us erAgent.match(" MSIE")) // for IE compatibility
newbutton.attac hEvent("onclick ",removelin e);
else
newbutton.addEv entListener("cl ick",removeline ,false);
This is a very bad way of adding the event. You should never use the
userAgent string to determine what methods are used. Use feature detection
instead:

if( newbutton.addEv entListener ) {
newbutton.addEv entListener('cl ick',removeline ,false);
} else if( newbutton.attac hEvent ) {
newbutton.attac hEvent('onclick ',removeline);
}

You should make sure that you use feature detection before accessing
methods and properties, particularly those of DOM components. IE has
relatively poor support and feature testing is the most reliable way to
determine when fallbacks are necessarily. Using the userAgent string might
group well-behaved (read: standards implementing) browsers with IE, which
would prevent you from taking advantage of their features.
But IE doesn't pass nothing as a parameter for removeline().
Any suggestions?


The problem is that IE, unlike most other browsers, doesn't pass an event
object to event listeners. Instead, event data is held in a global event
object. A further problem is that IE's event object doesn't use the same
properties as the DOM interface, or Netscape's object (from JS v1.3). Your
handler would have to be written:

function removeline(evt) {
var rowSuffix;

evt = evt || window.event;
if( evt.target ) {
rowSuffix = evt.target.name ;
} else if( evt.srcElement ) {
rowSuffix = evt.srcElement. name;
}

var row=document.ge tElementById("r ow" + rowSuffix);
var tbody=document. getElementById( "items");
var olds=tbody.styl e.display;
tbody.style.dis play="none";
tbody.removeChi ld(row);
tbody.style.dis play=olds;
}

Hope that helps,
Mike

--
Michael Winter
M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #3
Michael Winter <M.******@bluey onder.co.invali d> writes:
The problem is that IE, unlike most other browsers, doesn't pass an
event object to event listeners.


Actually it does when you attech the listener with attachEvent.
Try this.
document.body.a ttachEvent("onc lick",
function(evt){a lert(evt.srcEle ment.tagName);} );
in IE 5+ (couldn't get IE 4 to work well enough to test it there).

It doesn't pass the event as argument when you assign the handler
directly to document.body.o nclick.

Now that attachEvent has started to look usefull, it's time to mention
the shortcomming: The value of "this" when the handler is called is
the global object, not the object that the handler is attached to
(also unlike assigning to onclick, and unlike how other browsers
treat addEventListene r - even if it is not part of the DOM spec.).

Otherwise I agree.
/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 #4
On Thu, 26 Feb 2004 21:34:33 +0100, Lasse Reichstein Nielsen
<lr*@hotpop.com > wrote:
Michael Winter <M.******@bluey onder.co.invali d> writes:
The problem is that IE, unlike most other browsers, doesn't pass an
event object to event listeners.
Actually it does when you attech the listener with attachEvent.


It does? Well I'll be...

I assumed that as it doesn't when you use the event properties, it
wouldn't with attachEvent - a sensible connection, I thought.

I wonder why the differences occur. Could it be because attachEvent allows
multiple, concurrent listeners?
Try this.
document.body.a ttachEvent("onc lick",
function(evt){a lert(evt.srcEle ment.tagName);} );
in IE 5+ (couldn't get IE 4 to work well enough to test it there).
According the MS' DHTML reference, attachEvent was implemented in IE 5. IE
4 will still depend on assignment to the event properties. The OP's code
should probably be extended to:

if( newbutton.addEv entListener ) {
newbutton.addEv entListener('cl ick',removeline ,false);
} else if( newbutton.attac hEvent ) {
newbutton.attac hEvent('onclick ',removeline);
} else {
newbutton.oncli ck = removeline;
}

if support for earlier browsers is required.
Now that attachEvent has started to look usefull, it's time to mention
the shortcomming: The value of "this" when the handler is called is
the global object, not the object that the handler is attached to
(also unlike assigning to onclick, and unlike how other browsers
treat addEventListene r - even if it is not part of the DOM spec.).


That is quite a shortcoming. I realise that one can simply use
event.srcElemen t, but this is so much more convenient. Is it mentioned
anywhere in the references, or something that you know through experience?

Mike
[OT]

I always wanted to know why MS even decided to use a single, global event
object. Do browsers use a threaded model to process events, rather than a
queue? Is there any advantage - not necessarily speed, but responsiveness
perhaps - after weighing in the added overhead? If so, IE makes that very
difficult as more development effort would be required in order to make
sure that an event read the correct data.

[More OT nonsense]

I like this quote from the attachEvent method description:

"If you attach multiple functions to the same event on the same
object, the functions are called in random order, immediately
after the object's event handler is called."

It's somewhat ambiguous. Functions are called in a random order. I know
it's the same with DOM listeners, but a better wording could have been
used. It also appears that functions added with attachEvent aren't event
handlers for the object and something else is, but what?

Finally, I like how references are called pointers in the MS docs.

--
Michael Winter
M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #5
Michael Winter <M.******@bluey onder.co.invali d> writes:

[not setting "this"]
That is quite a shortcoming. I realise that one can simply use
event.srcElemen t, but this is so much more convenient. Is it mentioned
anywhere in the references,
Don't know, actually :)
or something that you know through experience?
Just something I found out when experimenting.
[OT]

I always wanted to know why MS even decided to use a single, global
event object.
Javascript was (and is) single threaded, and the intrinsic event
handlers could already refer to the current event by the name "event",
so I guess MS just thought that was as good an implementation as any.
Even simpler than passing the event, and almost always as good.
Do browsers use a threaded model to process events,
rather than a queue?
Current browsers are definitly single threaded. Considering the target
audience (people who can put text together without knowing what they
are doing), avoiding concurrency issues is probably wise.
[More OT nonsense]

I like this quote from the attachEvent method description:

"If you attach multiple functions to the same event on the same
object, the functions are called in random order, immediately
after the object's event handler is called."

It's somewhat ambiguous. Functions are called in a random order.
Yes, badly written. "Arbitrary" would be better than "random".
I know it's the same with DOM listeners, but a better wording could
have been used. It also appears that functions added with
attachEvent aren't event handlers for the object and something else
is, but what?
Probably the intrinsic event/obj.onclick function.
Finally, I like how references are called pointers in the MS docs.


:)

/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
On Thu, 26 Feb 2004 22:42:40 +0100, Lasse Reichstein Nielsen
<lr*@hotpop.com > wrote:
Michael Winter <M.******@bluey onder.co.invali d> writes:

[not setting "this"]
That is quite a shortcoming. I realise that one can simply use
event.srcElemen t, but this is so much more convenient. Is it mentioned
anywhere in the references,


Don't know, actually :)


I couldn't find it from a brief look around the various event-related
methods, so it might be written at a "guide" level (compare Netscape's
guides vs. references), rather than in the reference. I certainly hope
they mention it somewhere.

[snip]
I always wanted to know why MS even decided to use a single, global
event object.


Javascript was (and is) single threaded, and the intrinsic event
handlers could already refer to the current event by the name "event",
so I guess MS just thought that was as good an implementation as any.
Even simpler than passing the event, and almost always as good.
Do browsers use a threaded model to process events,
rather than a queue?


Current browsers are definitly single threaded. Considering the target
audience (people who can put text together without knowing what they
are doing), avoiding concurrency issues is probably wise.


I suppose, from an abstract point of view, I always think of events as
concurrent. It just seems natural. I might also be my exposure to
interrupts on the x86 - I don't know. To introduce a queue system appears
to disrupt the spontaneity that an event-oriented system would imply.

That said, I can't think of a system on the PC at the moment (other than
low-level interrupts) that uses concurrent event handling. Windows is
built on a queue system. I remember that Java threads the Swing UI, but it
still uses queuing for events, doesn't it? I forget (I really need to get
back to Java). I haven't touched programming on Unix-based systems, yet so
I can't comment there. I don't have a Mac, either.
It also appears that functions added with attachEvent aren't event
handlers for the object and something else is, but what?


Probably the intrinsic event/obj.onclick function.


I think I meant that as a rhetorical question. I can't quite remember (I
blame my current fever).

I certainly guessed that the intrinsic event would be considered the
"event handler" in that context, but it might have been nice for Microsoft
to mention it, especially as functions added with attachEvent still
"handle" events.

Mike

--
Michael Winter
M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #7

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

Similar topics

303
17589
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b. Yahoo store was originally written in Lisp. c. Emacs The issues with these will probably come up, so I might as well mention them myself (which will also make this a more balanced
5
2250
by: Thelma Lubkin | last post by:
I have a form/subform with the common one-to-many relationship. The form allows user to display records and move to other records via the selector, to add,delete, and edit them, with the related records displayed in the subform going along for the ride. The parent form's recordset has fields string integer COLORNAME CLASSSIZE and a few more that aren't relevant here.
5
1426
by: Brian Henry | last post by:
I have a page which reads an article from the database it has 1 text box, 2 dropdown lists, and a longreat HTML text box. I load the information from the database when the page is set to edit mode from a query string action=edit, now when i click on the update button it does the update event, the problem is, it still has the old unedited data in memory... and places the old stuff back into the database (saw this when debugging) the SQL is...
3
3872
by: Michael Glass | last post by:
I'm working on an ASP.Net web app using VS2005 and the .Net 2.0 framework, and I have a serious problem with the page I'm currently working on. The page has, among other things, two FormViews and a GridView control, each with its own SqlDataSource. FormView1 talks to my Opportunity table and has an ItemTemplate and an EditItemTemplate. FormView2 talks to my Activities table and has an ItemTemplate, InsertItemTemplate and an...
1
1591
by: Tom | last post by:
I am writing a Windows service in VB.NET... I am using two applicatons - the actual service, and then an additional 'control app' (Windows Forms) that can be used to stop, start, monitor, etc the service. Using the ServiceController class, I see that it is easy to get a limited amount of information INTO a service (such as using Custom Commands). Now let's reverse that - How does one get information OUT of a Windows service? For...
2
1864
by: Thorgal | last post by:
Hello all I have 2 questions First: I'm trying to print a Listview from an mdichild but how can i address this listview. For example, FrmMain is my Main form. In this Main form I have several mdichildren.
0
1458
by: =?Utf-8?B?UHVjY2E=?= | last post by:
-- Hi, I'm using vs2005,. .net 2.0 for windows applicaiton. I'm doing drag and drop of 1 row of data at a time between 2 datagridview controls. I'm using the myDataGridView.DragDrop event to get the row info as follow: DataGridView.HitTestInfor rowInfo = myDataGridView.HitTest(e.X, e.Y); rowInfo.RowIndex is the value I use to determin which row the drop occur at the target datagridview but I'm getting wrong row information. Why is that...
13
3053
by: SAL | last post by:
Okay, don't bash me to hard for my design on this app, it's my first web app and it's in production. My basic design is using Datatables created via the designer with a business logic class in between the datatable and ObjectDataSources. In one page I had a Gridview with select enabled. When an row in the grid is selected, I retrieve the SelectedValue, store the value in a Session variable and redirect the response to another web page,...
4
5702
by: imaloner | last post by:
I am posting two threads because I have two different problems, but both have the same background information. Common Background Information: I am trying to rebuild code for a working, commercially sold application with only partial build instructions. The previous maintainer of the code (a mixture of C and C++) is no longer with the company, but when he built the code he used MSVC++, and though I am not certain of the version he was ...
0
8380
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8816
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8497
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8598
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
7310
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
6162
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
5627
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
4150
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
2721
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

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.