[Project_owners] finding the <form/> of an <input/>

Alex Vincent ajvincent at gmail.com
Wed Mar 22 07:20:10 EST 2006


Eric, it's part of DOM Level 1 HTML.  It'll work even in IE.  :-)

On 3/22/06, Eric H. Jung <grimholtz at yahoo.com> wrote:
>
>
> --- HJ <bugs4hj at netscape.net> wrote:
>
> > Eric H. Jung wrote:
> > > Hi,
> > >
> > > Given an <input/> field, I'm trying to determine the <form/> in which it's contained. I've
> > written
> > > this recursive function:
> > >
> > > /** Returns null if there is no form **/
> > > findForm : function(node) {
> > >   // |node| is an <input type="text"/> field
> > >   if (node.nodeName == "FORM")
> > >     return node;
> > >   return node.parentNode ? this.findFormName(node.parentNode) : null;
> > > },
> > >
> > > This works for all pages I've tried except this one:
> > http://passwordmaker.org/proto/eraseme.html.
> > > In that case, the function returns null. I don't understand why it's not working. Anyone care
> > to
> > > take a look?
> >
> > Doesn't just node.parentNode work for this?
>
> No, because the DOM might look like this:
>
> <form><div><input/></div></form>
>
> in which case, node.parentNode = <div/>
> But the question is now moot since I've learned about the form attribute of input elements. Oops,
> I didn't test if that works in Mozilla... just Firefox.
>
> _______________________________________________
> Project_owners mailing list
> Project_owners at mozdev.org
> http://mozdev.org/mailman/listinfo/project_owners
>


--
"The first step in confirming there is a bug in someone else's work is
confirming there are no bugs in your own."
-- Alexander J. Vincent, June 30, 2001


More information about the Project_owners mailing list