![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
So, I found myself iterating through form elements today. This code worked just fine on FireFox:
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:
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.
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.
(no subject)
Date: 2006-07-21 06:24 pm (UTC)(no subject)
Date: 2006-07-21 06:26 pm (UTC)PHP is just fine. It's executed on the server side and therefore doesn't break in different browsers.
(no subject)
Date: 2006-07-23 09:56 pm (UTC)(no subject)
Date: 2006-07-23 10:20 pm (UTC)Then I say the standard is a little screwed up.
I come from a world (PHP) where for and foreach is just two different ways of iterating through the same data set. I pretty much considered those two operations to be similar, and to produce the same output on a scalar array.
I guess this is one more reason why I hate Javascript.
(no subject)
Date: 2006-07-24 07:35 am (UTC)In Javascript, the foreach construct iterates over all members and fields of the object. This is the only way to find out what all is in an object.
(no subject)
Date: 2006-08-28 08:39 pm (UTC)What didn't work:
for(i in myobject) {
...
}
What did work:
var i;
for(i in myobject) {
...
}
or (only inside the scope of the for loop)
for(var i in myobject) {
...
}