469,348 Members | 1,384 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,348 developers. It's quick & easy.

2 ways to call even-what is the difference?

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("onreadystatec hange", function()
{setIPandDetach (event.srcElement,currentRowID)}

thanks!
Aug 6 '08 #1
2 1268
"Montezuma's Daughter" <Ur*********@gmail.comwrites:
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("onreadystatec hange", 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
--
Lasse Reichstein Nielsen
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Aug 6 '08 #2
On Aug 5, 10:03*pm, Lasse Reichstein Nielsen <l...@hotpop.comwrote:
"Montezuma's Daughter" <Urania.m...@gmail.comwrites:
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+.
Well, sort of. getElementById is still buggy in IE8.

http://www.gtalbot.org/BrowserBugsSe...ersusName.html

Garrett
>
/L
Aug 6 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

22 posts views Thread by Peter Ammon | last post: by
5 posts views Thread by Seong-Kook Shin | last post: by
7 posts views Thread by J-T | last post: by
17 posts views Thread by Xah Lee | last post: by
20 posts views Thread by elderic | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.