This project is archived and is in readonly mode.

#582 ✓invalid

form.elements == form in IE

Reported by Brenton | January 29th, 2009 @ 04:29 AM | in 2.0 (closed)


A bug in IE can cause an infinite loop when using $$(form.elements). The workaround is to instead use this expression: $(this).getElements('input, select, textarea');

Problem description:

In most browsers, form.elements returns an HTMLCollection of the form's widgets.

In IE, form.elements returns the form, form[i] returns a form widget and form.length returns the number of widgets in a form. Even though that's a completely screwed up implementation, many pure JavaScript developers will never notice the difference. This still works in IE:

for (var i = 0; i <= form.elements.length; i++)

Bug demonstration:

I encountered this bug while trying to backport HTML 5's checkValidity functions. Both the form and its widgets have a checkValidity method. Consider now this psuedocode:

form.checkValidity = function(){

var widgets = $$(this.elements);
for (var i = 0; i < widgets.length; i++)


In IE, widgets[0].checkValidity() == form.checkValidity. You'll get an infinite loop with a stack overflow.

I'm not sure that this is the type of thing we can fix in MooTools, but I wanted to submit a ticket to assist anyone who runs into this bug in the future.

Comments and changes to this ticket

  • Valerio

    Valerio February 18th, 2009 @ 03:47 AM

    • State changed from “new” to “invalid”

    Yes, unfortunately this isnt something we can, or want to, fix. Just use the standard dom methods, and forget form.elements ever existed :)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

People watching this ticket