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

Matthew Wilson matthew at mjwilson.demon.co.uk
Tue Mar 21 20:20:57 EST 2006


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?

The DOM inspector shows that the form is not a direct ancestor of the 
input element in the constructed DOM.

The table contains the form element directly, whilst the input is 
contained inside the TBODY element. (Although there is no TBODY tag in 
the document, a TBODY element is constructed in the DOM, since the spec 
says that the start tag is optional).

Matthew Wilson



More information about the Project_owners mailing list