2 ways to call even-what is the difference?

  • Thread starter Montezuma's Daughter
  • Start date
M

Montezuma's Daughter

Hi All
I wanted to know what is the difference between:

1.getting an object

the first worked for me and the other didn't
var Subform = document.getElementById("Items2");

var Subform =document.all("Items2")

2.I was tryng to do attachedEvent, again the first one worked and the
other didn't, I would like to understand why.
I didn't get any error jus didn't work

var Subform = document.getElementById("Items2");
Subform.onreadystatechange = function() {setIPandDetach
(event.srcElement,currentRowID)} ;


var Subform =document.all("Items2")
document.all("Subform").attachEvent("onreadystatechange", function()
{setIPandDetach (event.srcElement,currentRowID)}

thanks!
 
L

Lasse Reichstein Nielsen

Montezuma's Daughter said:
I wanted to know what is the difference between:

1.getting an object

the first worked for me and the other didn't
var Subform = document.getElementById("Items2");

var Subform =document.all("Items2")

In which browser?

The former is the W3C DOM standard method for finding an element
by its id. It works in all modern browsers and in IE 5+.

The latter is the Microsoft proprietary method for finding an
element by its id (or name). It works in IE 4, and most new browsers
emulate the document.all collection - at least if you use it as
document.all["Items2"]
instead of as a function.

Use the former, but if document.getElementById doesn't exist, you
might want to fallback to document.all (if that exists).
2.I was tryng to do attachedEvent, again the first one worked and the
other didn't, I would like to understand why.
I didn't get any error jus didn't work

var Subform = document.getElementById("Items2");
Subform.onreadystatechange = function() {setIPandDetach
(event.srcElement,currentRowID)} ;

This probably only worked in IE anyway. The "event" variable
is global in IE, but is passed as argument to the handler function
in most other browsers.
var Subform =document.all("Items2")
document.all("Subform").attachEvent("onreadystatechange", function()
{setIPandDetach (event.srcElement,currentRowID)}

Do you mean to do 'document.all("Subform")'?
Why not just "Subform.attachEvent(...)"?

Your code is IE specific and won't work well, if at all, in most other
browsers.

/L
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,141
Messages
2,570,814
Members
47,360
Latest member
kathdev

Latest Threads

Top