Iterating through form elements

Iterating through form elements to add or remove elements of the form is tricky at best.

I'm looking at code I wrote about a year ago. I was so proud of its complexity. Now, it has come to bite me in the ass.

Long story short: the form.elements array will hold the same references to the elements in Firefox, even after they get removed from the form (via DOM). Not sure what the spec says it should be, but it's certainly confusing. If the element is no longer attached to the form node, it's not part of it. On the other hand, IE will update the array and always give you the elements that belong to the form, so if you remove an element, your iterator will be screwed.

Which one is it? If an element is removed from the form.elements array, should the reference to it still be in the array? Beats me.

Back to writing cross-bullshit code.

No comments: