Connecting Tech Pros Worldwide Forums | Help | Site Map

getElementsByTagName and doctype

otto
Guest
 
Posts: n/a
#1: Jul 23 '05
I'm a little new to the new DOM and using getElementsByTagName.
I'm trying to write code that returns an input tag based on its name
(for the sake of this example, I'm calling it xyz.)

I'm trying the following code:

function getxyx(){
var checks = document.getElementsByTagName('input');
for(var i=0;i<=checks.length;i++){
if(/xyz/.test(checks[i].getAttribute('name'))){
var mycheckbox = checks[i];
}
}
return mycheckbox;
}

The problem is that checks.length is returning 0. The html document
doesn't have any doctype at the moment. What doctype(s) can I use? Is
there a better way to do this?

Thanks.


otto
Guest
 
Posts: n/a
#2: Jul 23 '05

re: getElementsByTagName and doctype


Nevermind. I figured it out. It wasn't the doctype at all. It had to do
with the fact that I was calling the script from window.onload, but it
was attached to a cgi which was not buffering as it rendered. In other
words, the input collection was not yet present when the javascript
function was called.

Closed Thread