How not to iterate through form elements in Javascript on Internet Explorer

So, I found myself iterating through form elements today. This code worked just fine on FireFox:

for (key in form.elements) {
   var element = form.elements[key];

So, you'd think that would work in MSIE too, right? Noooo... trying to iterate through the elements that way in MSIE would cause it to pick up methods, language settings, and all sorts of other things not normally found in the elements array. Instead, I had to do this:

for (var i=0; i < form.elements.length; i++) {
   var element = form.elements[i];

And strangely enough, form.elements.length returns only the number of elements in the form, and not methods or whatever else the coming up before.

Oh well, at least I got done the task I was supposed to complete at work today. That's the important part.

Average: 4 (2 votes)
Your rating: None